-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Fix pickling of std(in, out, err) streams #45
Conversation
@@ -551,12 +551,15 @@ def save_file(pickler, obj): | |||
if obj.closed: | |||
position = None | |||
else: | |||
position = obj.tell() | |||
if obj in (sys.__stdout__, sys.__stderr__, sys.__stdin__): | |||
position = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that files ever have a negative tell()
Not sure setting the For
So, it's probably the right thing to do… and probably safe to do. Probably. |
Which version of python is that? Python 3.4.1 (default, May 19 2014, 17:23:49)
[GCC 4.9.0 20140507 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> f=sys.stdin
>>> f.read(3)
asdfghjkl
'asd'
>>> f.tell()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
io.UnsupportedOperation: underlying stream is not seekable Python 2.7.6 (default, Feb 26 2014, 12:07:17)
[GCC 4.8.2 20140206 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> f=sys.stdin
>>> f.read(3)
asdfghjkl
'asd'
>>> f.tell()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 29] Illegal seek |
@@ -340,7 +340,7 @@ def _create_filehandle(name, mode, position, closed, open=open): # buffering=0 | |||
raise UnpicklingError(err) | |||
#XXX: python default is closed '<uninitialized file>' file/mode | |||
if closed: f.close() | |||
else: f.seek(position) | |||
elif position >= 0: f.seek(position) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The position is only set if it is non negative
Sorry, I clipped that off…
|
Maybe its a mac - linux difference? |
Probably not. More likely a new "feature" since yours is Feb 2014 and mine is a Nov 2013 build |
Nope. I'm wrong, you are right. http://www.gossamer-threads.com/lists/python/python/99983 |
It seems like a fine thing to do, as if you are pickling within a single session, the stdin queue will be preserved. If you dump_session (or go off-processor), I'd assume the queue getting cleaned out might be ok.
This is indeed what happens by not setting the position.
But it also seems like that would be the case for setting the position as well. Since, the queue seems to be maintained as long as you don't seek. |
Fix pickling of std(in, out, err) streams
@matsjoyce: I'm sending you an email about a new release, and some etc. |
Fixes one of the problems in pickling
sys
as encounted in #41. As you cannotfile.tell()
a standard stream, this pr stops dill from trying and failing with anIOError
.