thread execution order

exarkun at divmod.com exarkun at divmod.com
Thu Sep 30 17:27:24 CEST 2004


On Thu, 30 Sep 2004 15:33:06 +0200, "Axel Mittendorf" <newsreply at transfertech.de> wrote:
>Hi, I have an app that writes text messages into a pipe and reads it out.
> Other programs write into this pipe too. Sometimes the pipe is full and
> my app freezes if it wants to write in that moment. It is not an option
> for me to open the pipe with O_NONBLOCK, so I thought I could
> use threads. Always when something shall be written into the pipe a new
> thread is created. These threads may hang on os.write, but they'll write out
> the data ASAP.
> See the example below (I substituted os.write with lock.acquire(1)).
> But if the pipe was full, three threads were created (all hang on os.write)
> and
> now the pipe is emptied, which one will write its data at first? The threads
> ordered by the time of thier creation (first no 1 then no 2,3,4 ... n) or
> just one of them
> (not ordered, maybe no4 then no1 and then no3)?
> I ask this since the order of the messages is important.

  The order is non-deterministic.  It will depend on such things as your platform, the underlying thread library, the load on the system at the time, and even how quickly or slowly the process reading the pipe actually reads, among other things.

  Could you explain why it is not an option to use a non-blocking pipe?

  Jp



More information about the Python-list mailing list