This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rshakh
Recipients asvetlov, rshakh, yselivanov
Date 2020-03-03.18:24:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583259870.1.0.174919125514.issue39839@roundup.psfhosted.org>
In-reply-to
Content
#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()
History
Date User Action Args
2020-03-03 18:24:30rshakhsetrecipients: + rshakh, asvetlov, yselivanov
2020-03-03 18:24:30rshakhsetmessageid: <1583259870.1.0.174919125514.issue39839@roundup.psfhosted.org>
2020-03-03 18:24:30rshakhlinkissue39839 messages
2020-03-03 18:24:29rshakhcreate