How do I check for pending UDP input?

Peter Hansen peter at engcorp.com
Thu Mar 13 15:37:49 EST 2003


Colin Brown wrote:
> 
> Hi, I am developing a multi-process application for theatrical lighting
> using Python and communicate between processes via UDP.
> 
> I need to keep some of the connections asynchronous and need to
> be able to either get the last packet sent or return an empty string.
> 
> My current code uses select with a small timeout to read in outstanding
> packets until a timeout occurs returning the previous packet read if any.
> 
> This is not elegant. Does anyone have experience with using SIOCINQ
> and IOCTLS in Python to find if a datagram is pending?

What's not elegant?  Select should return instantly when the socket
on which you are waiting becomes "readable" (as opposed to how you 
appear to describe it, where it always waits until the timeout before
returning).  This is the accepted way of doing this sort of thing, 
so you should probably redefine "elegant" and be happy. :-)

-Peter




More information about the Python-list mailing list