creating a block file for file-like object

Iain iain.murchland at gmail.com
Tue Nov 11 00:48:39 EST 2008


> Perhaps the parent should open the pipe for reading, before calling
> TroublesomeFunction. If the parent then dies, the child will get a "broken
> pipe" signal, which by default should kill it.

Yeah, that seems to work well, I think. Thanks for the help! I also
realised the child process was continuing and returning when I didn't
really want it to. So for anyone else who stumbles across this, it
ended up being

pipename = os.tmpnam()
os.mkfifo(pipename)
pid = os.fork()
if pid==0:
  fifoobj = open(pipename,"w")
  fifoobj.write(streamobj.read())
  fifoobj.close()
  os.unlink(pipename)
  os._exit(os.EX_OK)
else:
  fifoopen = open(pipename,"r")
  TroublesomeFunction(pipename)



More information about the Python-list mailing list