[PATCH 4/4] test_stopped: skip when not running in main_thread

0 views
Skip to first unread message

Rob Browning

unread,
Jun 22, 2026, 6:30:36 PM (3 days ago) Jun 22
to bup-...@googlegroups.com
This test was frequently failing in CI:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test/int/test_helpers.py:156: in stubborn_sleep
orig_term = signal(SIGTERM, SIG_IGN)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

signalnum = <Signals.SIGTERM: 15>, handler = <Handlers.SIG_IGN: 1>

@_wraps(_signal.signal)
def signal(signalnum, handler):
> handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
E ValueError: signal only works in main thread of the main interpreter

/usr/lib/python3.10/signal.py:56: ValueError
--------------------------- Captured stderr teardown ---------------------------

It looks like pytest and/or xdist are sometimes running tests in other
threads, so just skip the test when that's the case. (The test hasn't
failed locally with or without pytest -n, and isn't being skipped with
the guard.)

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---

Pushed to main.

test/int/test_helpers.py | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/test/int/test_helpers.py b/test/int/test_helpers.py
index c4c46eb4..a3b448ec 100644
--- a/test/int/test_helpers.py
+++ b/test/int/test_helpers.py
@@ -1,6 +1,7 @@

from signal import SIG_IGN, SIGKILL, SIGTERM, signal
from subprocess import Popen
+from threading import current_thread, main_thread
from time import tzset
import os, os.path

@@ -149,6 +150,9 @@ def test_finalized():


def test_stopped():
+ if current_thread() != main_thread():
+ pytest.skip('cannot set signal handler')
+ return False

def stubborn_sleep():
# restore_signals=False avoids the the possibility that we try to
--
2.47.3

Reply all
Reply to author
Forward
0 new messages