我需要轮询MSSQL数据库来观察正在运行的作业的状态。我想每隔X秒运行一次状态检查以查看status = done。我正在尝试使用线程模块。我用一些简单的打印语句测试了线程模块,它似乎可行,但是当我在我的pymssql脚本中尝试时,它不会。以设定的间隔Python轮询MSSQL
def watcher_query(cursor):
print 'Watching'
return cursor.execute(""" select *
from some_table' """)
def is_it_done(row):
if row['status'] == 'done':
return row['the_id'], True
else:
return row['the_id'], False
def d(cur):
watcher_query(cur)
for row in cur:
return is_it_done(row)[1]
threading.Timer(100, d).start()
def job_watch(server):
with pymssql.connect(server_info) as conn:
with conn.cursor(as_dict=True) as cur:
is_done = false
while is_done:
is_done = d(cur)
不管我怎么设置threading.Timer
给我看“看”语句打印不断。有没有更好的方法来设置轮询计时器?
我也尝试过使用Twisted来设置一个基本函数,它每X秒调用一个函数,直到满足某些条件。尽管如此,我还没有尝试使用MSSQL。