Skip to content

Commit d2bf46f

Browse files
committed
make imports thread-safe (by disabling import hook)
1 parent 977831a commit d2bf46f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

neovim/api/nvim.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ def out_write(self, msg, **kwargs):
392392

393393
def err_write(self, msg, **kwargs):
394394
"""Print `msg` as an error message."""
395-
if (self._session._loop_thread is not None and
396-
threading.current_thread() != self._session._loop_thread):
395+
if self._thread_invalid():
396+
# special case: if a non-main thread writes to stderr
397+
# i.e. due to an uncaught exception, pass it through
398+
# without raising an additional exception.
397399
self.async_call(self.err_write, msg, **kwargs)
398400
return
399401
return self.request('nvim_err_write', msg, **kwargs)
400402

403+
def _thread_invalid(self):
404+
return (self._session._loop_thread is not None and
405+
threading.current_thread() != self._session._loop_thread)
406+
401407
def quit(self, quit_command='qa!'):
402408
"""Send a quit command to Nvim.
403409

neovim/plugin/script_host.py

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def eval(self, expr):
208208
# This was copied/adapted from nvim-python help
209209
def path_hook(nvim):
210210
def _get_paths():
211+
if nvim._thread_invalid():
212+
return []
211213
return discover_runtime_directories(nvim)
212214

213215
def _find_module(fullname, oldtail, path):

0 commit comments

Comments
 (0)