Opened 15 years ago

Closed 7 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)

test.diff (1.1 KB ) - added by Jonas H. 12 years ago.
Test case that demonstrates the issue
fix.diff (967 bytes ) - added by Jonas H. 12 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by liangent, 15 years ago

note, this is a standalone python program, not a webapp in mod_python etc.

comment:2 by Jacob, 15 years ago

Please clarify what you mean be "cannot be saved" -- is there an error? If so, what is it?

comment:3 by liangent, 15 years ago

the field was left blank after saving

comment:4 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 by anonymous, 15 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 liangent, 15 years ago

sorry... i removed too much code...

  1. in line beginning with r.s.save, change r to rx, not the same as r above. rx is a model instance.
  1. in complete code, the child process invokes one of os.exec* after doing something, so the rest of parent code will not be executed.
  1. os.wait3() should be changed to os.wait3(0).
  1. i didn't understand 'the file would also attempt to save things and probably cause other problems', what did u mean?

comment:7 by Jacob, 15 years ago

milestone: 1.11.2

Pushing to 1.2: since there's a simple workaround -- change File(pipe) to ContentFile(pipe.read()).

comment:8 by Jacob, 14 years ago

Resolution: worksforme
Status: newclosed

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:9 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

comment:10 by Jonas H., 12 years ago

Cc: jonas-django@… added
Easy pickings: unset
Resolution: worksforme
Severity: Normal
Status: closedreopened
Type: Bug
UI/UX: unset
Version: 1.01.3

by Jonas H., 12 years ago

Attachment: test.diff added

Test case that demonstrates the issue

by Jonas H., 12 years ago

Attachment: fix.diff added

comment:11 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:12 by Tim Graham, 7 years ago

Resolution: worksforme
Status: newclosed
Summary: cannot save file from a pipecannot 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: See TracTickets for help on using tickets.
Back to Top