Skip to content

Commit

Permalink
fix: only set signal handlers from the main thread. #1312
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 26, 2022
1 parent 7b7712a commit 00da68e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion coverage/control.py
Expand Up @@ -11,6 +11,7 @@
import platform
import signal
import sys
import threading
import time
import warnings

Expand Down Expand Up @@ -528,8 +529,10 @@ def _init_for_start(self):
# 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
Expand Down

0 comments on commit 00da68e

Please sign in to comment.