Skip to content

Commit 00da68e

Browse files
committed
fix: only set signal handlers from the main thread. #1312
1 parent 7b7712a commit 00da68e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ This list is detailed and covers changes in each pre-release version.
2222
Unreleased
2323
----------
2424

25-
Nothing yet.
25+
- Fix: a signal handler was being set from multiple threads, causing an error:
26+
``ValueError: signal only works in main thread``. This is now fixed, closing
27+
`issue 1312`_.
28+
29+
.. _issue 1312: https://github.com/nedbat/coveragepy/issues/1312
2630

2731

2832
.. _changes_63:

coverage/control.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import platform
1212
import signal
1313
import sys
14+
import threading
1415
import time
1516
import warnings
1617

@@ -528,8 +529,10 @@ def _init_for_start(self):
528529
# It's useful to write debug info after initing for start.
529530
self._should_write_debug = True
530531

532+
# Register our clean-up handlers.
531533
atexit.register(self._atexit)
532-
if not env.WINDOWS:
534+
is_main = (threading.current_thread() == threading.main_thread())
535+
if is_main and not env.WINDOWS:
533536
# The Python docs seem to imply that SIGTERM works uniformly even
534537
# on Windows, but that's not my experience, and this agrees:
535538
# https://stackoverflow.com/questions/35772001/x/35792192#35792192

0 commit comments

Comments
 (0)