Use highest possible pickle protocol
This commit is contained in:
1 parent
ea71dedaa1
commit
282c6a2ba1
5 files changed
+59
-15
No files matched your search
+16
-5
@@ -446,9 +446,6 @@ if sys.version_info[:2] == (3, 3):
|
||||
pickle.loads = loads
|
||||
|
||||
|
||||
_PICKLE_PROTOCOL = 2
|
||||
|
||||
|
||||
def pickle_load(file):
|
||||
try:
|
||||
if is_py3:
|
||||
@@ -462,9 +459,9 @@ def pickle_load(file):
|
||||
raise
|
||||
|
||||
|
||||
def pickle_dump(data, file):
|
||||
def pickle_dump(data, file, protocol):
|
||||
try:
|
||||
pickle.dump(data, file, protocol=_PICKLE_PROTOCOL)
|
||||
pickle.dump(data, file, protocol)
|
||||
# On Python 3.3 flush throws sometimes an error even though the writing
|
||||
# operation should be completed.
|
||||
file.flush()
|
||||
@@ -476,6 +473,20 @@ def pickle_dump(data, file):
|
||||
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:
|
||||
|
||||
Reference in new issue
Block a user