WaitForMultipleObjects in Python.

Elbert Lev elbertlev at hotmail.com
Fri Jul 9 09:57:16 EDT 2004


David Bolen <db3l at fitlinxx.com> wrote in message news:<usmc29g0l.fsf at fitlinxx.com>...
> Peter Hansen <peter at engcorp.com> writes:
> 
.................
> What this doesn't let you do is have a single thread that can wake up
> to support multiple operations (such as an I/O thread handling data in
> both directions).  For that you pretty much need to use some
> OS-specific routines (such as a select based system for Unix, or the
> actual WaitForMultipleObjects under Windows).
> 
> For example, when I wanted a SerialIO object that supported full
> non-blocking I/O to the serial port under Windows, I ended up
> implementing a thread using overlapped I/O with
> WaitForMultipleObjects.  There just wasn't any equivalent in portable
> Python.

Strange. Why did you neen multiple threads? You could use Overlapped
I/O and IOCP (on Windows).
 
> This is definitely true as well, but there have been cases that I'd be
> just as happy to be able to wait on multiple Python threading objects
> (e.g., block a thread until something shows up on a Queue or one of
> several events fire without having to create a custom Queue message
> format to carry the extra events).

Let's be practical. For most cases server/worker thread model is what
you need. So queue communication is adequite. The only problem as I
see is that it is not Python Queue.Queue, but priority queue (waist in
this case), or a subclass of Queue.Queue, which allows to
post-to-head. I  understand, that this is NOT THE SAME AS
WaitForMultipleObjects, but close enough, for every day usage. If this
is not what you want, you probably are using a wrong language for the
job.

Java gurus: how this is done in java? Java - straight from the box
does not have such primitives.

Lev



More information about the Python-list mailing list