[issue39839] Non-working error handler when creating a task with assigning a variable
Рустам Шах
report at bugs.python.org
Tue Mar 3 13:24:30 EST 2020
New submission from Рустам Шах <shahrustam98 at 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 <report at bugs.python.org>
<https://bugs.python.org/issue39839>
_______________________________________
More information about the Python-bugs-list
mailing list