偶尔我会遇到一个问题,对sybase的查询需要很长时间。我想等待30秒左右,然后超时。下面是我的代码:
import Sybase
db = Sybase.connect('server','name','pass','database')
c = db.cursor()
c.execute("select statement that takes a long time")
list1 = c.fetchall()
print list1
如何重写代码,以便在查询耗时超过30秒时,生成一个空的list1?
发布于 2015-04-02 10:45:51
我认为有两种可能性:
在您的情况下,2个选项:
def func():
db = Sybase.connect('server','name','pass','database')
c = db.cursor()
c.execute("select statement that takes a long time")
list1 = c.fetchall()
print list1
A = KThread(target=func)
A.start()
time.sleep(30)
if not A.isAlive():
A.kill()
GL!
https://stackoverflow.com/questions/29396308
复制相似问题