If time.monotonic() is yielded from a generator that is passed to asyncio.ensure_future a segfault occurs when it's scheduled.
The example below shows time.monotonic called in the generator, however the segfault will also occur if a function is called (not a lambda) that uses time.monotonic.
I've tested on Python 3.6 and 3.7.0b4.
For example:
import asyncio
import time
import faulthandler
faulthandler.enable()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
# Note that ensure_future argument is generator
# which yields time.monotonic() return value
tasks = [asyncio.ensure_future(
time.monotonic()
for i in range(1)
)]
results_future = asyncio.gather(*tasks)
# Segmentation fault
results = loop.run_until_complete(results_future)
The fault handler output:
Fatal Python error: Segmentation fault
Current thread 0x00007f4b7a042b88 (most recent call first):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88 in _run
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1738 in _run_once
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 521 in run_forever
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 553 in run_until_complete
File "/test-seg.py", line 19 in <module>
Segmentation fault (core dumped)
An example with time.monotonic call nested in a function:
import asyncio
import time
import faulthandler
def bad():
return {'nested': time.monotonic()}
faulthandler.enable()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
tasks = [asyncio.ensure_future(
bad()
for i in range(1)
)]
results_future = asyncio.gather(*tasks)
# Segmentation fault
results = loop.run_until_complete(results_future)
|