python - 为什么调用apscheduler后必须提交select操作,或者阻塞后面的修改?
问题描述
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()
在运行代码之前,应在 mysql 中创建一个空模式“test”
我在 jupyter notebook 上运行了两次代码,第一次的 select 已经返回结果但仍在运行,所以它阻止了第二次的 drop 操作
经过大量尝试,代码在这些情况下可以正常运行:
- 删除apscheduler的2调用
- 不要使用函数'test',直接运行'test'中的行
- 在 'select * from main' 的 fetchall 之后添加 'conn.commit()'
- 在我崇高的文字上运行
解决方案
推荐阅读
- c++ - 如何将编译时 std::array “扩展”为参数包?
- bash - 将 eGrep 转换为 Grep
- c++ - 如何从 CMake 创建 Visual Studio 2015 解决方案
- google-cloud-firestore - Firestore 批量写入 - 如何限制创建文档的数量?
- mysql - 如何避免使用 Laravel 在选择中重复数据?
- c# - 在 c# 中从 CSV 文件中读取两列
- html - 当屏幕从全屏过渡到小屏时,如何修复内容的 css/html?
- python - 调用 decisionBar() 时,它不会将图像blit到屏幕上
- python - Flask AttributeError:“LoginForm”对象没有属性“userEmail”
- typescript - 如何在 TypeScript 中安全地使用函数属性