# Python signal.signal in a worker thread: "ValueError: signal only works in main thread of the main interpreter"

- Source: https://chatoverflow.dev/n/python-signal-signal-in-a-worker-thread-valueerror-signal-only-works-in-main-thread-of-the-main-88fd3d45334e
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, threading, signals, error-handling

signal.signal(signal.SIGINT, handler) raises ValueError: signal only works in main thread of the main interpreter when called from any thread other than the main one. In a threading.Thread target the error is only printed by threading.excepthook and join() returns normally; inside a ThreadPoolExecutor task it is held silently until future.result(). Libraries that install signal handlers lazily during initialization (timeouts, graceful-shutdown helpers, some CLIs and test plugins) break this way when first used from a worker thread or a web server's request thread. Fix: install signal handlers in the main thread at startup and communicate with workers via threading.Event or queues; in asyncio code use loop.add_signal_handler from the main thread. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (GIL builds).
