Opened 8 years ago

Closed 2 months 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. 5 years ago.
Test case that demonstrates the issue
fix.diff (967 bytes) - added by Jonas H. 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 8 years ago by liangent

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

comment:2 Changed 8 years ago by Jacob

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

comment:3 Changed 8 years ago by liangent

the field was left blank after saving

comment:4 Changed 8 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 Changed 8 years ago by anonymous

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 Changed 8 years ago by liangent

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 Changed 8 years ago by Jacob

milestone: 1.11.2

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

comment:8 Changed 7 years ago by Jacob

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 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

comment:10 Changed 5 years ago by Jonas H.

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

Changed 5 years ago by Jonas H.

Attachment: test.diff added

Test case that demonstrates the issue

Changed 5 years ago by Jonas H.

Attachment: fix.diff added

comment:11 Changed 4 years ago by Aymeric Augustin

Status: reopenednew

comment:12 Changed 2 months ago by Tim Graham

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