asyncio icon indicating copy to clipboard operation
asyncio copied to clipboard

log_destroy_pending parameter for asyncio.async/asyncio.ensure_future

Open neumond opened this issue 9 years ago • 0 comments

Hi, I'm making lots of background tasks via asyncio.async, but it often floods output with tons of

Task was destroyed but it is pending!
task: <Task pending coro=<task() running at try.py:6> wait_for=<Future pending cb=[Task._wakeup()]>>

Reading the source I've found private property of task, _log_destroy_pending, if I change the value to False, no more annoying output happens. But the code looks a bit ugly and hacky. Would be cool to have a parameter when I really don't care if task could be killed pending.

import asyncio


@asyncio.coroutine
def task():
    yield from asyncio.sleep(1)


@asyncio.coroutine
def main():
    f = asyncio.async(task(), loop=loop)
    # f._log_destroy_pending = False  # supresses printing and fixes the issue

    # how about a separate parameter?
    # asyncio.async(task(), loop=loop, log_destroy_pending=False)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

neumond avatar Apr 28 '16 00:04 neumond