Python open a named pipe == hanging?

Rob Williscroft rtw at freenet.co.uk
Thu Aug 3 17:03:11 EDT 2006


Rochester wrote in news:op.tdp5i6tsh12lye at cadet.mshome.net in 
comp.lang.python:

>      I just found out that the general open file mechanism doesn't work
>      for named pipes (fifo).  Say I wrote something like this and it
>      simply hangs python:
> 
> #!/usr/bin/python
> 
> import os
> 
> os.mkfifo('my_fifo')
> 
> open('my_fifo', 'r+').write('some strings.')
> x = os.popen('cat my_fifo').read()
> 

You will probably need to use os.open()

w = os.open( 'my_fifo', os.O_WRONLY )
r = os.open( 'my_fifo', os.O_RDONLY )

though I'm using windows now, so can't test it.

> print x
> 
> 
>      I know I could use a tempfile instead of a fifo in this very
>      simple case, I just want to know is there a standard way of
>      handling fifos withing python.

See also os.pipe()

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list