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):
        print(self.__class__.__name__)
        pass
    @asyncio.coroutine
    def greet_every_one_seconds(self, db):
            print('Hello World, one second.')
            fut = asyncio.sleep(1,result=4)
            a = yield from fut
            print(a)

    def a(self):

        loop = asyncio.get_event_loop()


        task = loop.create_task(self.greet_every_one_seconds(self.db_presell))
        #How can i wait for the task until complete?

    @asyncio.coroutine
    def greet_every_two_seconds(self):
        while True:
            self.a()
            print('Hello World, two seconds.')
            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