-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Bump the default pickle protocol in shelve #78385
Comments
The default pickle protocol is 4 now. But shelve still uses the pickle protocol 3. Shouldn't it be bumped? Shouldn't shelve use pickle.DEFAULT_PROTOCOL by default? Disadvantages:
|
I wrote a short script to see the impact of file size depending on the protocol: import shelve
import os.path
print("== Short value ==")
for proto in (0, 1, 2, 3, 4, 5):
filename = 'shelve-picklev%s' % proto
with shelve.open(filename, protocol=proto) as db:
assert db._protocol == proto
for x in range(1000):
db[str(x)] = str(x)
print(f'Protocol {proto}: {os.path.getsize(filename)} bytes')
os.unlink(filename)
print()
print("== Large value ==")
large_value = [str(x) for x in range(1000)]
for proto in (0, 1, 2, 3, 4, 5):
filename = 'shelve-picklev%s' % proto
with shelve.open(filename, protocol=proto) as db:
assert db._protocol == proto
for x in range(10):
db[str(x)] = large_value
print(f'Protocol {proto}: {os.path.getsize(filename)} bytes')
os.unlink(filename) Output with Python 3.9.0b1 (on Fedora 32): == Large value == For short string values, protocol 0 produces smaller files than protocol 1 and higher. For large value, protocol 4 and higher produce smaller files than protocol 3 and lower. |
I've opened #22751 to fix this, I know there was already a PR, but it seems to have been abandoned. |
It has not been abandoned. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: