1
import mysql.connector
from apscheduler.schedulers.background import BackgroundScheduler

def progress_bar():
    pass

def test():
    conn = mysql.connector.connect(user='root', password='123456', database='test', auth_plugin='mysql_native_password')
    cursor = conn.cursor()

    cursor.execute('drop table if exists main')
    conn.commit()
    cursor.execute('create table main (mid int)')
    conn.commit()
    cursor.execute('insert into main values (1)')
    conn.commit()

    sched = BackgroundScheduler()
    job = sched.add_job(progress_bar, 'interval', seconds=1)

    cursor.execute('select * from main')
    print(cursor.fetchall())
    #conn.commit()


test()

Before running the code, an empty schema 'test' should be created in mysql

I run the code on jupyter notebook twice, the select in first time has return the result but still running, so it block the drop operation in second time

After trying a lot, the code can run normally in these situations:

  1. delete the 2 call of apscheduler
  2. don't use the function 'test', run the lines in 'test' directly
  3. add 'conn.commit()' after the fetchall of 'select * from main'
  4. run on my sublime text
Zeus0123
  • 11
  • 2

0 Answers0