You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault while calling loop.create_future in finalizer (__del__) when a custom sys.excepthook is used #143
Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes, in fact, it is reproducible only when the asyncio debug is enabled
When using uvloop and having a custom sys.excepthook which uses a variable from the outer scope, which has a finalizer (the __del__ method) that creates a new future using AbstractEventLoop.create_future() method, Python interpreter crashes with a segmentation fault.
Example code:
#!/usr/bin/env python3importasyncioimportsysimportuvloopclassLoopWrapper():
def__init__(self, loop):
self.loop=loopdef__del__(self):
print('finalizing', self.loop)
self.loop.create_future() # assertion fails hereasyncdefstore_event_loop(loop):
wrapped_loop=LoopWrapper(loop)
defcustom_excepthook(*exc_info):
print('unhandled_exception', exc_info)
# commenting the below line causes the failed assertion to disappearprint(wrapped_loop)
sys.excepthook=custom_excepthookif__name__=='__main__':
# commenting the below line causes the failed assertion to disappearasyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
event_loop=asyncio.get_event_loop()
# commenting the below line disables the assertionsevent_loop.set_debug(True)
event_loop.run_until_complete(store_event_loop(event_loop))
When uvloop is not used, the code fails at this AttributeError:
Traceback (most recent call last):
File "./uvloop_test.py", line 13, in __del__
File "/usr/lib/python3.6/asyncio/base_events.py", line 276, in create_future
AttributeError: 'NoneType' object has no attribute 'Future'
When a Python interpreter compiled with --with-pydebug option is used, it crashes on the following assertion failure:
(gdb) py-bt
Traceback (most recent call first):
<built-in method create_future of Loop object at remote 0x7f7ecfafe048>
File "./uvloop_test.py", line 13, in __del__
self.loop.create_future() # assertion fails here
The issue here is that uvloop causes Python interpreter to crash. I believe that a regular Python exception should be raised instead.
Apart from addressing this issue, if someone can explain the details of what is happening in the example code mentioned above, in particular why it fails even without uvloop and why a finalizer triggered from a custom sys.excepthook is not able to call create_future(), it would also be helpful.
Activity
1st1 commentedon May 18, 2018
This seems to be a bug, I'll take a look. Thanks for reporting it!
1st1 commentedon May 23, 2018
This is actually a CPython bug :) Thanks for reporting. Closing this in favour of python/cpython#7080.