[New-bugs-announce] [issue39256] Exception handler set by set_exception_handler is called only when I run coroutine by create_task

Conrad report at bugs.python.org
Wed Jan 8 04:41:47 EST 2020


New submission from Conrad <conradhch at hotmail.com>:

import asyncio

async def test():
    raise Exception("Something goes wrong")

async def main():
    #Un-comment either 1 of the following 3 lines
    # await test() # will not call exception_handler
    # await asyncio.gather(test()) # will not call exception_handler
    # asyncio.create_task(test()) # will call exception_handler

    await asyncio.sleep(5)

def exception_handler(loop, context):
    exception = context.get("exception", None)
    print("exception_handler", exception)

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.set_exception_handler(exception_handler)
    loop.run_until_complete(main())
    print("Job done")

----------
components: asyncio
messages: 359571
nosy: asvetlov, conraddd, yselivanov
priority: normal
severity: normal
status: open
title: Exception handler set by set_exception_handler is called only when I run coroutine by create_task
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39256>
_______________________________________


More information about the New-bugs-announce mailing list