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 billyfoster
Recipients billyfoster, gvanrossum, yselivanov
Date 2016-09-25.18:37:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474828647.42.0.633955971909.issue28274@psf.upfronthosting.co.za>
In-reply-to
Content
I found a very strange bug in asyncio where whether exception handlers are called depends on whether a task is stored.

To illustrate, the following code works as expected, printing out that it made it to the exception handler:

import asyncio
async def run():
    raise RuntimeError
def exception_handler(loop, context):
    print('Made it to exception handler.')
loop = asyncio.get_event_loop()
loop.set_exception_handler(exception_handler)
loop.create_task(run())
loop.run_forever()

However, if you take that exact same code but store the task that is returned from create_task, the exception handler will NOT be called:

import asyncio
async def run():
    raise RuntimeError
def exception_handler(loop, context):
    print('Made it to exception handler.')
loop = asyncio.get_event_loop()
loop.set_exception_handler(exception_handler)
task = loop.create_task(run())
loop.run_forever()

This is completely bizarre, and I have been unable to track down the reason.
History
Date User Action Args
2016-09-25 18:37:27billyfostersetrecipients: + billyfoster, gvanrossum, yselivanov
2016-09-25 18:37:27billyfostersetmessageid: <1474828647.42.0.633955971909.issue28274@psf.upfronthosting.co.za>
2016-09-25 18:37:27billyfosterlinkissue28274 messages
2016-09-25 18:37:27billyfostercreate