[Twisted-Python] Opening a fifo
Hi, I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor. Is there a straight-forward mechanism to asynchronously open the fifo? Or will I have to do something with threads? Thanks, pt.
Paul Thomas wrote:
Hi,
I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor.
Either of: fd = os.open('thefifo', os.O_RDONLY | os.O_NONBLOCK) fd = os.open('thefifo', os.O_RDWR) ...will return immediately, Try "man fifo" for a description of the vagaries. A listenFIFO would be handy in Twisted. It's tedious doing this manually.
On 14 Nov 2008, at 09:47, Phil Mayers wrote:
Paul Thomas wrote:
Hi, I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor.
Either of:
fd = os.open('thefifo', os.O_RDONLY | os.O_NONBLOCK) fd = os.open('thefifo', os.O_RDWR)
...will return immediately,
Try "man fifo" for a description of the vagaries.
I've tried RDWR and I get errors in writing. I really need O_WRONLY, and that fails with O_NONBLOCK unless the other end is open. Maybe I'll chase down the RDWR problem again. Ta.
Paul Thomas wrote:
On 14 Nov 2008, at 09:47, Phil Mayers wrote:
Paul Thomas wrote:
Hi, I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor.
Either of:
fd = os.open('thefifo', os.O_RDONLY | os.O_NONBLOCK) fd = os.open('thefifo', os.O_RDWR)
...will return immediately,
Try "man fifo" for a description of the vagaries.
I've tried RDWR and I get errors in writing. I really need O_WRONLY, and that fails with O_NONBLOCK unless the other end is open. Maybe I'll chase down the RDWR problem again.
Really? It works for me in a repl: [pjm3@wildfire ~]$ mkfifo blah [pjm3@wildfire ~]$ python
import os fd = os.open('blah', os.O_RDWR) os.write(fd, 'a') 1
What errors are you getting? Possibly Twisted is getting confused because the fd is "readable" as well as "writeable". Do you have sample code that's failing?
On 14 Nov 2008, at 11:00, Phil Mayers wrote:
Paul Thomas wrote:
On 14 Nov 2008, at 09:47, Phil Mayers wrote:
Paul Thomas wrote:
Hi, I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor.
Either of:
fd = os.open('thefifo', os.O_RDONLY | os.O_NONBLOCK) fd = os.open('thefifo', os.O_RDWR)
...will return immediately,
Try "man fifo" for a description of the vagaries. I've tried RDWR and I get errors in writing. I really need O_WRONLY, and that fails with O_NONBLOCK unless the other end is open. Maybe I'll chase down the RDWR problem again.
Really? It works for me in a repl:
[pjm3@wildfire ~]$ mkfifo blah [pjm3@wildfire ~]$ python
import os fd = os.open('blah', os.O_RDWR) os.write(fd, 'a') 1
What errors are you getting? Possibly Twisted is getting confused because the fd is "readable" as well as "writeable".
Do you have sample code that's failing?
I'll have to wait til Monday to try it out again. I thought the problem was to do with the other process opening the read end between the open and the write. But maybe it was a case of not testing what I thought I was testing. Still, so long as I know that twisted doesn't provide anything I might have missed, and that you think it should work, I can focus on fixing it instead of working around it. Thanks.
On 14 Nov 2008, at 11:39, Paul Thomas wrote:
On 14 Nov 2008, at 11:00, Phil Mayers wrote:
Paul Thomas wrote:
On 14 Nov 2008, at 09:47, Phil Mayers wrote:
Paul Thomas wrote:
Hi, I've run into a small problem where my twisted application needs to open a fifo to talk to another process. On Linux at least, the open blocks until the other end of the fifo is opened and this is blocking my reactor.
[snip]
fd = os.open('thefifo', os.O_RDWR)
...will return immediately,
[snip]
I'll have to wait til Monday to try it out again. I thought the problem was to do with the other process opening the read end between the open and the write. But maybe it was a case of not testing what I thought I was testing.
This works just fine: fd = os.open('thefifo', os.O_RDWR | os.O_NONBLOCK) thanks for your help. Paul.
participants (2)
-
Paul Thomas -
Phil Mayers