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
marshal.load() reads entire remaining file instead of just next value #58652
Comments
In Python 3.2, if you write several values to a file with multiple calls to marshal.dump(), and then try to read them back, the first marshal.load() returns the first value, but reads to the end of the file, so subsequent calls to marshal.load() raise an EOFError. E.g.: import marshal
f = open("test", "wb")
marshal.dump(("hello", 1), f)
marshal.dump(("there", 2), f)
marshal.dump(("friend", 3), f)
f.close()
f = open("test", "rb")
print(marshal.load(f)) # ('hello', 1)
print(marshal.load(f)) # ERROR This page seems to indicate this was also a bug in Python 3.1: http://www.velocityreviews.com/forums/t728526-python-3-1-2-and-marshal.html |
You are correct.
I got:
Python 3.1.2 (release31-maint, Dec 9 2011, 20:50:50)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import marshall
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named marshall
>>> import marshal
>>> f = open("test", "wb")
>>> marshal.dump(("hello", 1), f)
20
>>> marshal.dump(("there", 2), f)
20
>>> marshal.dump(("friend", 3), f)
21
>>> f.close()
>>> f = open("test", "rb")
>>> print(marshal.load(f))
('hello', 1)
>>> print(marshal.load(f))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError: EOF read where object expected
>>> |
The previous test was on linux mint 10 (Julia) with python 3.1.2 Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import marshal
>>> f = open('t', 'wb')
>>> marshal.dump(('skd', 1), f)
18
>>> marshal.dump(('slkd', 2), f)
19
>>> marshal.dump('lkdss', 3), f)
SyntaxError: invalid syntax
>>> marshal.dump(('lskda', 3), f)
20
>>> f.close()
>>> f = open('t', 'rb')
>>> print(marshal.load(f))
('skd', 1)
>>> print(marshal.load(f))
('slkd', 2)
>>> print(marshal.load(f))
('lskda', 3)
>>> print(marshal.load(f))
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
print(marshal.load(f))
EOFError: EOF read where object expected
>>> As you can see, this problem appearently does not apply to 3.2.2 |
This is a duplicate of bpo-12291. 3.1 is in security-fix only mode. |
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: