Opened 16 years ago
Closed 8 years ago
#10541 closed Bug (worksforme)
cannot save file from a pipe on Python 2
Reported by: | liangent | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | jonas-django@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
code like this:
r, w = os.pipe() if os.fork() == 0: # child os.close(r) os.dup2(w, sys.stdout.fileno()) print '123' os.close(w) os.wait3() fo = os.fdopen(r, 'rb') r.s.save('sout', File(fo)) os.close(r)
the content in pipe cannot be saved. however if i change File(fo)
to ContentFile(fo.read())
, it can be saved correctly
Attachments (2)
Change History (14)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Please clarify what you mean be "cannot be saved" -- is there an error? If so, what is it?
comment:4 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:5 by , 16 years ago
I think you're code is considerably confused. You attempt to access the "s" attribute from r, which is an integer file descriptor, the branch for the child does not exit and runs the parent's code. As a result, wait3 is called in the child which has no children, also getting confused. Failing that, the file would also attempt to save things and probably cause other problems --- perhaps related to your bug report. (Finally, os.wait3() requires an argument in my version of Python (2.5). The documentation for that version states otherwise, so it could just be inaccurate.)
Could you provide sample code that actually runs?
comment:6 by , 16 years ago
sorry... i removed too much code...
- in line beginning with
r.s.save
, changer
torx
, not the same asr
above.rx
is a model instance.
- in complete code, the child process invokes one of
os.exec*
after doing something, so the rest of parent code will not be executed.
os.wait3()
should be changed toos.wait3(0)
.
- i didn't understand 'the file would also attempt to save things and probably cause other problems', what did u mean?
comment:7 by , 16 years ago
milestone: | 1.1 → 1.2 |
---|
Pushing to 1.2: since there's a simple workaround -- change File(pipe)
to ContentFile(pipe.read())
.
comment:8 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I can't reproduce this, and I still haven't seen what the error liangent is getting, so I'm closing this ticket. liangent, please feel free to reopen if you can provide a complete failing example *and* the error that you're seeing.
comment:10 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Resolution: | worksforme |
Severity: | → Normal |
Status: | closed → reopened |
Type: | → Bug |
UI/UX: | unset |
Version: | 1.0 → 1.3 |
by , 13 years ago
comment:11 by , 12 years ago
Status: | reopened → new |
---|
comment:12 by , 8 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Summary: | cannot save file from a pipe → cannot save file from a pipe on Python 2 |
The test passes on Python 3 and given the lack of interest in this issue, I think it's fine to close
note, this is a standalone python program, not a webapp in mod_python etc.