New submission from Рустам Шах <shahrusta...@gmail.com>: #This example does not work due to assigning the task to a variable
import asyncio import logging def handle_exception(loop, context): msg = context.get("exception", context["message"]) logging.error("Caught exception: %s", msg) async def test(): await asyncio.sleep(1) raise Exception("Crash.") def main(): loop = asyncio.get_event_loop() loop.set_exception_handler(handle_exception) # if removed "task = " - exception handler will work. task = loop.create_task(test()) try: loop.run_forever() finally: loop.close() if __name__ == "__main__": main() ---------- components: asyncio messages: 363287 nosy: asvetlov, yselivanov, Рустам Шах priority: normal severity: normal status: open title: Non-working error handler when creating a task with assigning a variable versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39839> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com