Skip to content

Commit 4a4fe00

Browse files
committed
Only configure signals if running in the main thread
It seems signal watchers cant be set on other threads
1 parent ca2c8e8 commit 4a4fe00

File tree

1 file changed

+7
-3
lines changed
  • neovim/msgpack_rpc/event_loop

1 file changed

+7
-3
lines changed

neovim/msgpack_rpc/event_loop/base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Common code for event loop implementations."""
22
import logging
33
import signal
4+
import threading
45

56

67
logger = logging.getLogger(__name__)
@@ -11,6 +12,7 @@
1112
# which exits the program. To be able to restore the python interpreter to it's
1213
# default state, we keep a reference to the default handler
1314
default_int_handler = signal.getsignal(signal.SIGINT)
15+
main_thread = threading.current_thread()
1416

1517

1618
class BaseEventLoop(object):
@@ -131,12 +133,14 @@ def run(self, data_cb):
131133
self._error = None
132134
raise err
133135
self._on_data = data_cb
134-
self._setup_signals([signal.SIGINT, signal.SIGTERM])
136+
if threading.current_thread() == main_thread:
137+
self._setup_signals([signal.SIGINT, signal.SIGTERM])
135138
debug('Entering event loop')
136139
self._run()
137140
debug('Exited event loop')
138-
self._teardown_signals()
139-
signal.signal(signal.SIGINT, default_int_handler)
141+
if threading.current_thread() == main_thread:
142+
self._teardown_signals()
143+
signal.signal(signal.SIGINT, default_int_handler)
140144
self._on_data = None
141145

142146
def stop(self):

0 commit comments

Comments
 (0)