@
bluesky139 '''
class Worker(object):
def __init__(self,str):
self._name = str
self._installed = False
def install(self):
if self._installed:
print "%s: no need to start again.worker has been installed!" % self._name
else:
self._installed = True
ioloop.IOLoop.instance().add_callback(self.test)
print "%s: worker is installed" % self._name
@
gen.coroutine
def fetch(self,url):
req = HTTPRequest(url,connect_timeout=3,request_timeout=5)
client = httpclient.AsyncHTTPClient()
resp = yield gen.Task(client.fetch, req)
raise gen.Return(resp)
@
gen.coroutine
def exact(self,resp):
yield gen.sleep(5)
raise gen.Return(10)
@
gen.coroutine
def test(self):
if self._installed:
ioloop.IOLoop.instance().add_timeout(datetime.timedelta(microseconds=5000),self.test)
str = self._name
task_url = u'
http://api.caipiao.163.com/missNumber_trend.html?gameEn=kuai3' resp = yield self.fetch(task_url)
print "%s get resp already at %s" %(str,datetime.datetime.now())
staus = yield self.exact(resp)
print "callback!!!%s status returned %d at %s" %(str,staus,datetime.datetime.now())
if __name__ == '__main__':
arrs = ['aaa','bbb']
for arr in arrs:
worker = Worker(arr)
worker.install()
ioloop.IOLoop.instance().start()
'''
谢谢,还在找原因
请问 ioloop.IOLoop.instance().add_timeout(datetime.timedelta(microseconds=5000),self.test)
这个能让 test 方法定期执行么,测试结果这个间隔没有用