pygame and socket.recv

Hendrik van Rooyen mail at
Thu Apr 2 16:49:58 CEST 2009

"Aaron Brady" <cast..pi at> wrote:

On Apr 2, 1:19 am, "Hendrik van Rooyen" <m... at> wrote:

>> "Aaron Brady" <cast... at> wrote:

8< ---- stuff showing small packets and adequate bandwidth ----------

>> What does "some latency" mean? - barely visible jitter, or a half
>> second freeze?
>I've got a rather amateur loop keeping the frame rate capped at 40
>fps.  The game won't exceed that, but when it drops /below/ it, it can
>fall to 30 or 20 or 15 fps.  That was just a per-second averaging
>calculation; the bad freezes are about half a second.  I'll try to get
>a reading of individual calls to 'recv' that are themselves below the
>Here's the loop: wait half the time left, then half that, then half
>that, and so on, until less than 1/1000th second is left.
>        while 1:
>            tcurr= time.clock( )
>            delay= ( ( tprev+ secsperframe )- tcurr )* 0.5
>            if delay< 0.001:
>                break
>            time.sleep( delay )
>        tprev= tcurr
This will hand control to the OS more than once.  It may be 
worth it to try making a target "completion date" and to then
sleep the difference between now and then, once.

>I don't know if it could be responsible.  Would a mutex or Queue be
>better using a threading.Timer?

Good question - I don't know.  I am just assuming that the OS is somehow
giving you short shrift in its task scheduling.  Does anybody know what
the granularity of task swapping is in XP?  - Forty per second is only 25
milliseconds - Is a task more or less guaranteed to get a bite at the cherry 
in that time?  We need a windoze expert to tell us what the minimum time is
for swapping a task out and in.   If you are less than that time away from
your scheduled "completion date", it makes no sense to sleep...

>> What do you do when the total round trip time takes longer
>> than your target of one fortieth of a second?
>I want to know that too!

Well if you were to know that it has happened, it would make
sense to do the stuff immediately, and to reschedule your
future target "completion dates"

8< -------- more stuff showing adequate bandwidth ----------------

- Hendrik

More information about the Python-list mailing list