Skip to content

Commit df2b512

Browse files
committed
Fix the test
1 parent 066f8d3 commit df2b512

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/cysignals/tests.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ from libc.errno cimport errno
3535
from posix.signal cimport sigaltstack, stack_t, SS_ONSTACK
3636

3737
from cpython cimport PyErr_SetString
38+
from cpython.exc cimport PyErr_CheckSignals
3839

3940
from .signals cimport *
4041
from .memory cimport *
@@ -805,6 +806,13 @@ def test_interrupt_bomb(long n=100, long p=10):
805806
i = 0
806807
while True:
807808
try:
809+
# For some reason, without the line below, the exception
810+
# will be detected too late (outside the try/except block)
811+
# and the KeyboardInterrupt will be leaked outside,
812+
# making the test fail.
813+
# We can't really call PyErr_CheckSignals() from inside
814+
# sig_on() because it does not hold the GIL.
815+
PyErr_CheckSignals()
808816
with nogil:
809817
sig_on()
810818
ms_sleep(1000)
@@ -1124,7 +1132,7 @@ def test_sig_block_outside_sig_on(long delay=DEFAULT_DELAY):
11241132
sig_unblock()
11251133

11261134
try:
1127-
sig_on() # Interrupt caught here
1135+
PyErr_CheckSignals() # Interrupt caught here
11281136
except KeyboardInterrupt:
11291137
return "Success"
11301138
abort() # This should not be reached

0 commit comments

Comments
 (0)