Opened 7 years ago

Last modified 3 years ago

#10541 new Bug

cannot save file from a pipe

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


code like this:

r, w = os.pipe()
if os.fork() == 0: # child
    os.dup2(w, sys.stdout.fileno())
    print '123'


fo = os.fdopen(r, 'rb')'sout', File(fo))

the content in pipe cannot be saved. however if i change File(fo) to ContentFile(, it can be saved correctly

Attachments (2)

test.diff (1.1 KB) - added by jonash 5 years ago.
Test case that demonstrates the issue
fix.diff (967 bytes) - added by jonash 4 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by liangent

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 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 7 years ago by liangent

the field was left blank after saving

comment:4 Changed 7 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 7 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 7 years ago by liangent

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

  1. in line beginning with, 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 7 years ago by jacob

  • milestone changed from 1.1 to 1.2

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

comment:8 Changed 6 years ago by jacob

  • Resolution set to worksforme
  • Status changed from new to 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:9 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

comment:10 Changed 5 years ago by jonash

  • Cc jonas-django@… added
  • Easy pickings unset
  • Resolution worksforme deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to Bug
  • UI/UX unset
  • Version changed from 1.0 to 1.3

Changed 5 years ago by jonash

Test case that demonstrates the issue

Changed 4 years ago by jonash

comment:11 Changed 3 years ago by aaugustin

  • Status changed from reopened to new
Note: See TracTickets for help on using tickets.
Back to Top