Skip to content

Commit

Permalink
make imports thread-safe (by disabling import hook)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Oct 8, 2018
1 parent 977831a commit d2bf46f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions neovim/api/nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,18 @@ def out_write(self, msg, **kwargs):

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

def _thread_invalid(self):
return (self._session._loop_thread is not None and
threading.current_thread() != self._session._loop_thread)

def quit(self, quit_command='qa!'):
"""Send a quit command to Nvim.
Expand Down
2 changes: 2 additions & 0 deletions neovim/plugin/script_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def eval(self, expr):
# This was copied/adapted from nvim-python help
def path_hook(nvim):
def _get_paths():
if nvim._thread_invalid():
return []
return discover_runtime_directories(nvim)

def _find_module(fullname, oldtail, path):
Expand Down

0 comments on commit d2bf46f

Please sign in to comment.