Python open a named pipe == hanging?

Antoon Pardon apardon at forel.vub.ac.be
Fri Aug 4 13:41:57 EDT 2006


On 2006-08-04, Rochester <rochester1976 at gmail.com> wrote:
> Thank you for your advise.  So, it turns out that fifos are quite useless  
> in Python programming then, which is quite disappointing to me :-(
>
> I am not saying that I _have to_ use fifo, afterall it is a rather odd  
> thingy not in fasion since the last iceage... I am just disappointed by  
> the fact that the old plain Bash seems to excel Python in this special  
> aspect.

It doesn't.

> I am new to Python and much more comfortable in Bash programming.  A  
> simple Bash script like this would take the advantage of a fifo, hence  
> reduce the overhead of unneccesarry temporary files creation:
>
> #!/bin/bash
>
> mkfifo my_fifo
> echo "this is a string in my fifo!" > my_fifo &
> cat my_fifo
> rm my_fifo
>
> Isn't it neat?

Look you put the echo in the background, because otherwise your script
would block. Nothing stops you from starting a thread in python to open
the fifo in write mode, the thread would block but the main program
could still continue.

There also is the os.pipe and os.popen calls that may be more usefull
in specific cases.

-- 
Antoon Pardon



More information about the Python-list mailing list