coroutine not recognized #12171
-
Note: I have posted this question in https://github.com/peterhinch/micropython-async also. But not sure if it is actively monitored by Peter. And since uasyncio is a platform agnostic library, I thought this forum may be suitable. I am new to async programming in micropython. However, to get a basic hang of it I did some experiments with creating and stopping tasks at different time intervals within main(), which is surrendered in an event loop by asyncio.run(main). After few trial and errors it worked. So, I though I got the idea. Basically, what I thought is that once the main is surrendered to the event loop, I can create objects inside the main as usual, and class methods can create_task with a coro. Those tasks will get scheduled in the event loop. I even created a async Timer class, which also works. Emboldened by my newly acquired success, I tried creating an Updater class, that will periodically poll a http server for updates. I am using async http class and asyc timer class. When I use the 'http.get' method as the coro in create_task, it works.
Output:
So, Periodic async http call is working with Async Timer. However, because I have used http_get coro as argument of create_task, I am not able to capture the return response from http_get call, So, I wrapped http_get inside a coro named _get_manifest. And instead of using http_get as coro, I tried using _get_manifest coro with the create_task.
But I got unexpected result. Output:
According to https://github.com/peterhinch/micropython-async/blob/master/v3/docs/TUTORIAL.md#22-coroutines-and-tasks,
The _get_manifest follows the above template. It is defined with async def, and has await statement
So, Why _get_manifest is not identified as a coro, when used in create_task? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need task = asyncio.create_task(self._get_manifest()) |
Beta Was this translation helpful? Give feedback.
You need