How do I check for pending UDP input?

Colin Brown cbrown at metservice.com
Thu Mar 13 18:18:49 EST 2003


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3E70EC1D.557A4E4F at engcorp.com...
> 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

I probably need to clarify things a little. The UDP receiver is being used
in a number of different places. Some of the circuits have little traffic
but
others have more data than I can handle within that application and I am
wanting to just use the last packet sent. I know that "select" returns as
soon
as "readable" data is present. The problem I have come across is that if I
do not empty the UDP receive buffer some of the comms slows right down
because I am not clearing the circuit faster than the data comes in. Using
"select" with a timeout means that I always have to read until I get an
empty
string back upon a timeout to clear the buildup. Thus I am always incurring
the "timeout read". Yes, it works but if I could peek the receive buffer I
would not have to incur the timeout delay and thereby achieve proper
asynchronous operation.

Colin Brown
PyNZ








More information about the Python-list mailing list