Message363287
#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() |
|
Date |
User |
Action |
Args |
2020-03-03 18:24:30 | rshakh | set | recipients:
+ rshakh, asvetlov, yselivanov |
2020-03-03 18:24:30 | rshakh | set | messageid: <1583259870.1.0.174919125514.issue39839@roundup.psfhosted.org> |
2020-03-03 18:24:30 | rshakh | link | issue39839 messages |
2020-03-03 18:24:29 | rshakh | create | |
|