creating a block file for file-like object

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Nov 10 09:08:27 CET 2008

In message
<15d2b10c-0df8-4791-874c-339cc65a076c at>, Iain

> Well I did work out *a* solution this way:
>   pipename = os.tmpnam()
>   os.mkfifo(pipename)
>   pid = os.fork()
>   if pid==0:
>     fifoobj = open(pipename,"w")
>     fifoobj.write(
>     fifoobj.close()
>     os.unlink(pipename)
>   else:
>     TroublesomeFunction(pipename)

OK, so TroublesomeFunction is reading from the pipe while the child is
writing? Naturally you'd get a block if you tried to do both in the same

> And it doesn't fail very gracefully in that if
> TroublesomeFunction stops before attempting to open/read the pipe,
> then the child process stays hung waiting for the other end of the
> pipe to open.

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.

More information about the Python-list mailing list