Python 扫数据库的程序,遇到问题,求教!

2016-05-23 15:59:23 +08:00
 yfl168648

一个定时调度的程序,现在遇到的问题是, next_exec_date 我在 navicat 中更新成老时间,程序并不能扫描到。 重启后就能扫描到。新手 python ,还不是很溜,求大家帮忙看看 main 方法里起了一个线程, run 方法如下 主要代码:

	def run(self):
		try:
			conn = mysql.connector.connect(**config.dbconfig)
		except mysql.connector.Error as e:
			logging.error( str(e))
			self.stop()
		
		sql = 'select * '
		sql += ' from task where next_exec_date < now() and state=1 limit 0,10'
		cursor = conn.cursor()	
		
		while not self.thread_stop:	
			cursor.execute(sql)
			result = cursor.fetchall()
			logging.debug("扫描到%s 个任务...",len(result))
            
			time.sleep(self.interval)
		#end while
		cursor.close()
		conn.close()
2834 次点击
所在节点    编程
2 条回复
lbp0200
2016-05-23 16:54:42 +08:00
黑产
yfl168648
2016-05-23 17:38:09 +08:00
搞定了。。事务隔离级别的问题。
set global tx_isolation='read-committed'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/280671

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX