Open
Description
Generators messes with signals handling support
This generator runs ok on CPython 3.7, but hangs on RustPython.
When hung, signals are ignored by RustPython:
# snippet.py
import signal
def _rescuer(*args, **kwargs):
raise TimeoutError('The test was hung. ' + str(args) + str(kwargs))
signal.signal(signal.SIGALRM, _rescuer)
signal.alarm(2)
print('SIGALRM set to 2sec ahead')
def gen4():
yield next(g)
g = gen4()
try:
next(g)
except ValueError as e:
assert 'generator already executing' in str(e), str(e)
else:
raise AssertionError
finally:
print('SIGALRM clear')
signal.alarm(0) # clear the alarm rescuer
On CPython 3.7:
$ python3.7 snippet.py
SIGALRM set to 2sec ahead
SIGALRM clear
$
On RustPython:
$ time cargo run snippet.py
Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Running `target/debug/rustpython snippet.py`
SIGALRM set to 2sec ahead
^C^C^C^T^Z
[1]+ Stopped cargo run snippet.py
real 0m14,156s
user 0m0,001s
sys 0m0,000s
$ fg
cargo run snippet.py
^Z
[1]+ Stopped cargo run tests/snippets/generator_test.py
$ kill %1
$
[1]+ Finished cargo run tests/snippets/generator_test.py
$
As shown above, there are two issues:
- Generator hanging in a strange way
- This hang makes signal handling to stop.
- RustPython failed to handle SIGALRM, SIGHUP and SIGINFO
- Note that SIGTERM was succeeded. There was no need to SIGKILL the hung process.
Python Documentation
Link to signal
documentation: https://docs.python.org/3/library/signal.html#example