HI,
i write a test program for create_task, see the following:

the function a() must be not coroutine,
How can i wait for the task until complete?

thanks!



import asyncio

class Test(object):
 def __init__(self):
 pass
 @asyncio.coroutine
 def greet_every_one_seconds(self, db):
 print('Hello World, is a task')
 a = yield from asyncio.sleep(1, result=3)
 print(a)
 return a
 def a(self):

 loop = asyncio.get_event_loop()
 task = loop.create_task(self.greet_every_one_seconds(self.db_presell))
 #
 #a = yield from asyncio.wait_for(t,50)

 @asyncio.coroutine
 def greet_every_two_seconds(self):
 while True:
 self.a()
 print('Hello World')
 yield from asyncio.sleep(2)


if __name__ == '__main__':
 test = Test()
 loop = asyncio.get_event_loop()
 try:
 loop.run_until_complete(test.greet_every_two_seconds())
 finally:
 loop.close()



Reply via email to