我需要輪詢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。