From fabd3c860a9a6428169b1976a07ae67e6dc2bd20 Mon Sep 17 00:00:00 2001 From: Jan Gosmann Date: Sat, 9 Jun 2018 12:11:06 -0400 Subject: [PATCH] Acquire lock when using Jedi. This should ensure thread safety, but might not give the best performance. It might be possible to skip processing of some requests if too many arrive in a short interval instead of processing all of them with a delay once the lock becomes available for each request. Addresses #975. --- CHANGES.rst | 1 + nengo_gui/completion.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7e06f86a..c456f37b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,7 @@ Release History 0.4.3 (unreleased) ================== +- Bugfix: thread-safety for jedi autocompletion - Bugfix: Handle authentication when connecting to multiple servers - Bugfix: Fail gracefully when binding server diff --git a/nengo_gui/completion.py b/nengo_gui/completion.py index 297ec4d1..4c74b36a 100644 --- a/nengo_gui/completion.py +++ b/nengo_gui/completion.py @@ -1,3 +1,4 @@ +import threading import warnings try: @@ -14,6 +15,9 @@ def completions(self): return [] +_jedi_lock = threading.Lock() + def get_completions(code, line, column, path=None): - script = Script(code, line, column, path=path) - return script.completions() + with _jedi_lock: + script = Script(code, line, column, path=path) + return script.completions()