集成开发环境:WingIDE5.1.4 暂不支持(WingIDE5.1.5开始支持),
import tornado #loop =tornado.ioloop.IOLoop.instance() #导入错误。这是由于tornado代码的问题。 from tornado.ioloop import IOLoop #正确的方式 loop = IOLoop.instance()
aysnc和await的用法:
import time async def long_time_proc(num): #asyncio.sleep(2) time.sleep(3) return hex(num) async def display_res(num): r = await long_time_proc(num) #await print("r:"+r, time.time()) loop = asyncio.get_event_loop() # Blocking call which returns when the display_date() coroutine is done loop.run_until_complete(display_res(6)) loop.run_until_complete(display_res(5)) loop.close()
与tornado的loop
import tornado loop =tornado.ioloop.IOLoop.instance() from tornado.ioloop import IOLoop loop = IOLoop.instance() def finished(): print ("ff") loop.add_future( display_res(6), finished ) loop.add_future( display_res(5), finished ) loop.start()
暂时通不过,参见:https://mail.python.org/pipermail/python-dev/2015-May/139851.html