Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert using highest possible pickle protocol #1164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions jedi/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ def loads(s, fix_imports=True, encoding="ASCII", errors="strict"):
pickle.loads = loads


# Use version 4 of the pickle protocol when support for Python 2.7 and 3.3 is
# dropped.
_PICKLE_PROTOCOL = 2


def pickle_load(file):
try:
if is_py3:
Expand All @@ -459,9 +464,9 @@ def pickle_load(file):
raise


def pickle_dump(data, file, protocol):
def pickle_dump(data, file):
try:
pickle.dump(data, file, protocol)
pickle.dump(data, file, protocol=_PICKLE_PROTOCOL)
# On Python 3.3 flush throws sometimes an error even though the writing
# operation should be completed.
file.flush()
Expand All @@ -473,20 +478,6 @@ def pickle_dump(data, file, protocol):
raise


# Determine the highest protocol version compatible for a given list of Python
# versions.
def highest_pickle_protocol(python_versions):
protocol = 4
for version in python_versions:
if version[0] == 2:
# The minimum protocol version for the versions of Python that we
# support (2.7 and 3.3+) is 2.
return 2
if version[1] < 4:
protocol = 3
return protocol


try:
from inspect import Parameter
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion jedi/api/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_evaluator_subprocess(self, evaluator):
return EvaluatorSubprocess(evaluator, self._get_subprocess())

def _get_subprocess(self):
return get_subprocess(self.executable, self.version_info)
return get_subprocess(self.executable)

@memoize_method
def get_sys_path(self):
Expand Down
21 changes: 8 additions & 13 deletions jedi/evaluate/compiled/subprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from functools import partial

from jedi._compatibility import queue, is_py3, force_unicode, \
pickle_dump, pickle_load, highest_pickle_protocol, GeneralizedPopen
pickle_dump, pickle_load, GeneralizedPopen
from jedi.cache import memoize_method
from jedi.evaluate.compiled.subprocess import functions
from jedi.evaluate.compiled.access import DirectObjectAccess, AccessPath, \
Expand All @@ -29,12 +29,11 @@
_MAIN_PATH = os.path.join(os.path.dirname(__file__), '__main__.py')


def get_subprocess(executable, version):
def get_subprocess(executable):
try:
return _subprocesses[executable]
except KeyError:
sub = _subprocesses[executable] = _CompiledSubprocess(executable,
version)
sub = _subprocesses[executable] = _CompiledSubprocess(executable)
return sub


Expand Down Expand Up @@ -126,11 +125,9 @@ def __del__(self):
class _CompiledSubprocess(object):
_crashed = False

def __init__(self, executable, version):
def __init__(self, executable):
self._executable = executable
self._evaluator_deletion_queue = queue.deque()
self._pickle_protocol = highest_pickle_protocol([sys.version_info,
version])

@property
@memoize_method
Expand All @@ -139,8 +136,7 @@ def _process(self):
args = (
self._executable,
_MAIN_PATH,
os.path.dirname(os.path.dirname(parso_path)),
str(self._pickle_protocol)
os.path.dirname(os.path.dirname(parso_path))
)
return GeneralizedPopen(
args,
Expand Down Expand Up @@ -194,7 +190,7 @@ def _send(self, evaluator_id, function, args=(), kwargs={}):

data = evaluator_id, function, args, kwargs
try:
pickle_dump(data, self._process.stdin, self._pickle_protocol)
pickle_dump(data, self._process.stdin)
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
Expand Down Expand Up @@ -240,12 +236,11 @@ def delete_evaluator(self, evaluator_id):


class Listener(object):
def __init__(self, pickle_protocol):
def __init__(self):
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
Expand Down Expand Up @@ -312,7 +307,7 @@ def listen(self):
except Exception as e:
result = True, traceback.format_exc(), e

pickle_dump(result, stdout, self._pickle_protocol)
pickle_dump(result, file=stdout)


class AccessHandle(object):
Expand Down
4 changes: 1 addition & 3 deletions jedi/evaluate/compiled/subprocess/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,5 @@ def load(name):
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(pickle_protocol).listen()
subprocess.Listener().listen()
26 changes: 0 additions & 26 deletions test/test_compatibility.py

This file was deleted.