Opened 6 years ago

Last modified 2 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

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 jonash 4 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 6 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 6 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 6 years ago by liangent

the field was left blank after saving

comment:4 Changed 6 years ago by jacob

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

comment:5 Changed 6 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 6 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 6 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(pipe.read()).

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 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

comment:10 Changed 4 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 4 years ago by jonash

Test case that demonstrates the issue

Changed 4 years ago by jonash

comment:11 Changed 2 years ago by aaugustin

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