diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-26 06:38:27 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-26 18:07:17 -0500 |
commit | 00da68ef1a0b4d43c003babae0cb8f91beaf06d2 (patch) | |
tree | bbb0bda7c22e27890a64a59f3c83076a98de99ea | |
parent | 7b7712ab34b6f0f9dc880be3cd668e67cf903f76 (diff) | |
download | python-coveragepy-git-00da68ef1a0b4d43c003babae0cb8f91beaf06d2.tar.gz |
fix: only set signal handlers from the main thread. #1312
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | coverage/control.py | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 0ab9f54f..9f0a451d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,7 +22,11 @@ This list is detailed and covers changes in each pre-release version. Unreleased ---------- -Nothing yet. +- Fix: a signal handler was being set from multiple threads, causing an error: + ``ValueError: signal only works in main thread``. This is now fixed, closing + `issue 1312`_. + +.. _issue 1312: https://github.com/nedbat/coveragepy/issues/1312 .. _changes_63: diff --git a/coverage/control.py b/coverage/control.py index 0f62198a..9dfa59fb 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -11,6 +11,7 @@ import os.path import platform import signal import sys +import threading import time import warnings @@ -528,8 +529,10 @@ class Coverage: # It's useful to write debug info after initing for start. self._should_write_debug = True + # Register our clean-up handlers. atexit.register(self._atexit) - if not env.WINDOWS: + is_main = (threading.current_thread() == threading.main_thread()) + if is_main and not env.WINDOWS: # The Python docs seem to imply that SIGTERM works uniformly even # on Windows, but that's not my experience, and this agrees: # https://stackoverflow.com/questions/35772001/x/35792192#35792192 |