Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51964

Re: Simulate `bash` behaviour using Python and named pipes.

Date 2013-08-05 15:51 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Simulate `bash` behaviour using Python and named pipes.
References <a4c08e1c-2915-48ed-a65d-2e1b89f28878@googlegroups.com> <mailman.209.1375711382.1251.python-list@python.org> <7f5c60c4-50c7-4a93-af22-5c8549f87461@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.211.1375714293.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 05/08/2013 15:11, Luca Cerone wrote:
> Hi MRAB, thanks for the reply!
>>
>> Opening the pipe for reading will block until it's also opened for
>> writing, and vice versa.
>>
>
> OK.
>
>>
>> In your bash code, 'ls' blocked until you ran 'cat', but because you
>> ran 'ls' in the background you didn't notice it!
>>
>>
> Right.
>>
>> In your Python code, the Python thread blocked on opening the pipe for
>> writing. It was waiting for another thread or process to open the pipe
>> for reading.
>
> OK. What you have written makes sense to me. So how do I overcome the block?
> As you said in bash I run the ls process in background. How do I do that in Python?
>
You need to ensure that the pipe is already open at the other end.

Why are you using a named pipe anyway?

If you're talking to another program, then that needs to be running
already, waiting for the connection, at the point that you open the
named pipe from this end.

If you're using a pipe _within_ a program (a queue would be better),
then you should opening for writing in one thread and for reading in
another.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 06:09 -0700
  Re: Simulate `bash` behaviour using Python and named pipes. Paul Wiseman <poalman@gmail.com> - 2013-08-05 14:39 +0100
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 06:51 -0700
  Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 15:03 +0100
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 07:11 -0700
      Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 15:51 +0100
        Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 08:27 -0700
          Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 17:08 +0100
            Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 09:54 -0700
              Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 20:45 +0100
                Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 14:47 -0700
                Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 23:42 +0100
                Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-06 09:25 -0700
                Re: Simulate `bash` behaviour using Python and named pipes. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-08-10 13:07 +1200
  Re: Simulate `bash` behaviour using Python and named pipes. Alister <alister.ware@ntlworld.com> - 2013-08-05 14:29 +0000
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 07:59 -0700
      Re: Simulate `bash` behaviour using Python and named pipes. Neil Cerutti <neilc@norwich.edu> - 2013-08-05 16:00 +0000

csiph-web