Hi,
I've a component that should download different things on different delays.
I've tried to create a component that on_join starts different coroutines to run the infinite loop that download, wait the delay and so on.
My problem is, when I quit my app, it spams a lot a "Tasks was never awaited" and, I've tried to await it in on_leave or on_disconnect, but it seems that, when the application quit, those events do not run.
so basically what it does is (simplified with only one loop, but I have 6 of those):
class Downloader:
def __init__(self, wamp_comp):
self._wamp = wamp_comp
self._session = None
self._wamp.on("join", self._initialize)
self._wamp.on("join", self._start_dl_loop)
async def _initialize(self, session, details):
self._session = session
async def _start_dl_loop(self, session, details):
await self.get_things(DEFAULT_DELAY)
async def get_things(self, delay_sec: float):
while True:
try:
# await aiohttp request
await asyncio.sleep(delay_sec)
and, when stop:
ERROR:project.endpoints.sync:
2018-12-14T10:45:39
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending coro=<Downloader._start_tasks_loop() running at ...> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f7eb6739138>()]> cb=[gather.<locals>._done_callback(3)() at /usr/lib64/python3.6/asyncio/tasks.py:622]>
2018-12-14T10:45:39 Task was destroyed but it is pending!
I also tried with something like
async def get_things(self, delay_sec: float):
loop = asyncio.get_event_loop()
print("working") # download
loop.call_later(delay_sec, functools.partial(self.get_things,
delay_sec))
but then it runs only once and complains the coroutine was never awaited.
Any advice on either how to use the infinite loop and not have problems on quit or doing something else like call_later (even if this is less performant because of the creation of task for each iteration)
Thanks a lot