How do I check for pending UDP input?

Colin Brown cbrown at metservice.com
Thu Mar 13 22:03:34 EST 2003


Thanks

Thinking outside the square, I like that. I will have to check that I
am not getting thread conflicts with other software if I do it this way
though.

Colin

"Dennis Lee Bieber" <wlfraed at ix.netcom.com> wrote in message
news:t4n7k-eg3.ln1 at beastie.ix.netcom.com...
> Colin Brown fed this fish to the penguins on Thursday 13 March 2003
> 03:18 pm:
>
> >
> > 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.
> >
>         I'm still not sure just what all is happening, but...
>
>         I'd suggest that you need to decouple the UDP handler from the
main
> application logic. Use a thread to read the UDP socket.
>
> {very rough psuedo-code}
>
> the UDP thread process (no initialization is shown)
>
> while 1:
>         last_pkt = skt.recv()   #no need for select, as long as the recv
is
>         theLock.acquire()       #blocked, theGlobalPkt contains the last
>         theGlobalPkt = last_pkt #packet received (or None)
>         theLock.release()
>
> and the main application
>
> theGlobalPkt = None
> #start the UDP thread here
> while 1:
>         theLock.acquire()
>         pkt = theGlobalPkt      #get the most recent received packet
>         theGlobalPkt = None     #assuming you don't want to process it
again
>         theLock.release()
>         # do all the time consuming stuff while the UDP thread keeps
>         # updating theGlobalPkt (which won't affect the local pkt
>         # until you've finished with it and go back to check theGlobalPkt
>
> --
>  > ============================================================== <
>  >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >      wulfraed at dm.net     |       Bestiaria Support Staff       <
>  > ============================================================== <
>  >        Bestiaria Home Page: http://www.beastie.dm.net/         <
>  >            Home Page: http://www.dm.net/~wulfraed/             <
>






More information about the Python-list mailing list