Merge pull request #1087 from tahoe-lafs/3741.pickle-versioning-python-3

Limit Pickle protocol to version supported by Python 2

Fixes ticket:3741
This commit is contained in:
Itamar Turner-Trauring 2021-06-16 13:40:16 -04:00 committed by GitHub
commit de76c1d8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -201,7 +201,9 @@ class CPUWatcher(service.MultiService, resource.Resource, Referenceable):
log.msg("error reading process %s (%s), ignoring" % (pid, name))
log.err()
try:
pickle.dump(self.history, open("history.pickle.tmp", "wb"))
# Newer protocols won't work in Python 2; when it is dropped,
# protocol v4 can be used (added in Python 3.4).
pickle.dump(self.history, open("history.pickle.tmp", "wb"), protocol=2)
os.rename("history.pickle.tmp", "history.pickle")
except:
pass

0
newsfragments/3741.minor Normal file
View File

View File

@ -252,7 +252,9 @@ class ShareCrawler(service.MultiService):
self.state["last-complete-prefix"] = last_complete_prefix
tmpfile = self.statefile + ".tmp"
with open(tmpfile, "wb") as f:
pickle.dump(self.state, f)
# Newer protocols won't work in Python 2; when it is dropped,
# protocol v4 can be used (added in Python 3.4).
pickle.dump(self.state, f, protocol=2)
fileutil.move_into_place(tmpfile, self.statefile)
def startService(self):

View File

@ -95,7 +95,9 @@ class LeaseCheckingCrawler(ShareCrawler):
if not os.path.exists(self.historyfile):
history = {} # cyclenum -> dict
with open(self.historyfile, "wb") as f:
pickle.dump(history, f)
# Newer protocols won't work in Python 2; when it is dropped,
# protocol v4 can be used (added in Python 3.4).
pickle.dump(history, f, protocol=2)
def create_empty_cycle_dict(self):
recovered = self.create_empty_recovered_dict()
@ -319,7 +321,9 @@ class LeaseCheckingCrawler(ShareCrawler):
oldcycles = sorted(history.keys())
del history[oldcycles[0]]
with open(self.historyfile, "wb") as f:
pickle.dump(history, f)
# Newer protocols won't work in Python 2; when it is dropped,
# protocol v4 can be used (added in Python 3.4).
pickle.dump(history, f, protocol=2)
def get_state(self):
"""In addition to the crawler state described in