1
0
forked from VimPlug/jedi

Use highest possible pickle protocol

This commit is contained in:
micbou
2018-06-20 14:55:04 +02:00
committed by Dave Halter
parent ea71dedaa1
commit 282c6a2ba1
5 changed files with 59 additions and 15 deletions

View File

@@ -17,7 +17,7 @@ import traceback
from functools import partial
from jedi._compatibility import queue, is_py3, force_unicode, \
pickle_dump, pickle_load, GeneralizedPopen
pickle_dump, pickle_load, highest_pickle_protocol, GeneralizedPopen
from jedi.cache import memoize_method
from jedi.evaluate.compiled.subprocess import functions
from jedi.evaluate.compiled.access import DirectObjectAccess, AccessPath, \
@@ -29,11 +29,12 @@ _subprocesses = {}
_MAIN_PATH = os.path.join(os.path.dirname(__file__), '__main__.py')
def get_subprocess(executable):
def get_subprocess(executable, version):
try:
return _subprocesses[executable]
except KeyError:
sub = _subprocesses[executable] = _CompiledSubprocess(executable)
sub = _subprocesses[executable] = _CompiledSubprocess(executable,
version)
return sub
@@ -125,9 +126,11 @@ class EvaluatorSubprocess(_EvaluatorProcess):
class _CompiledSubprocess(object):
_crashed = False
def __init__(self, executable):
def __init__(self, executable, version):
self._executable = executable
self._evaluator_deletion_queue = queue.deque()
self._pickle_protocol = highest_pickle_protocol([sys.version_info,
version])
@property
@memoize_method
@@ -136,7 +139,8 @@ class _CompiledSubprocess(object):
args = (
self._executable,
_MAIN_PATH,
os.path.dirname(os.path.dirname(parso_path))
os.path.dirname(os.path.dirname(parso_path)),
str(self._pickle_protocol)
)
return GeneralizedPopen(
args,
@@ -190,7 +194,7 @@ class _CompiledSubprocess(object):
data = evaluator_id, function, args, kwargs
try:
pickle_dump(data, self._process.stdin)
pickle_dump(data, self._process.stdin, self._pickle_protocol)
except (socket.error, IOError) as e:
# Once Python2 will be removed we can just use `BrokenPipeError`.
# Also, somehow in windows it returns EINVAL instead of EPIPE if
@@ -236,11 +240,12 @@ class _CompiledSubprocess(object):
class Listener(object):
def __init__(self):
def __init__(self, pickle_protocol):
self._evaluators = {}
# TODO refactor so we don't need to process anymore just handle
# controlling.
self._process = _EvaluatorProcess(Listener)
self._pickle_protocol = pickle_protocol
def _get_evaluator(self, function, evaluator_id):
from jedi.evaluate import Evaluator
@@ -307,7 +312,7 @@ class Listener(object):
except Exception as e:
result = True, traceback.format_exc(), e
pickle_dump(result, file=stdout)
pickle_dump(result, stdout, self._pickle_protocol)
class AccessHandle(object):

View File

@@ -45,5 +45,7 @@ else:
load('jedi')
from jedi.evaluate.compiled import subprocess # NOQA
# Retrieve the pickle protocol.
pickle_protocol = int(sys.argv[2])
# And finally start the client.
subprocess.Listener().listen()
subprocess.Listener(pickle_protocol).listen()