New submission from Conrad <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue39256>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com