Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9921 > unrolled thread

turtles slowing down

Started byEricC <ec97005@gmail.com>
First post2011-07-19 15:02 -0700
Last post2011-07-19 22:29 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  turtles slowing down EricC <ec97005@gmail.com> - 2011-07-19 15:02 -0700
    Re: turtles slowing down Terry Reedy <tjreedy@udel.edu> - 2011-07-19 22:29 -0400

#9921 — turtles slowing down

FromEricC <ec97005@gmail.com>
Date2011-07-19 15:02 -0700
Subjectturtles slowing down
Message-ID<d9ff7419-fed9-4e8f-b02f-2afd63e6d7d7@g3g2000prf.googlegroups.com>
Hi,

I am a newbie - I have been teaching myself Python 3 since a few
months ago. My “self assignments” include some purely for fun. Among
them was using the turtle module to have multiple turtles running
around on the screen.

Recently one such fun turtle “project” showed strange behavior that I
cannot understand – while I achieved my goals (multiple turtles
oscillate along random straight lines while changing colors), there
was a steady slowing down of turtles as time goes. Actually they
became so slow it is not even fun to look at.

To trouble shoot the problem by myself, I striped down the codes to
the minimal that reproduces the problem. In appearance as long as it
involves “fd()”, it steadily slows down.

The follows is the striped down version (no multiple turtles, no color
changes):

from turtle import *
import time

class Ball(Turtle):
    def __init__(self):
        Turtle.__init__(self)
        self.stepsize = 1
        self.steps = 100        # number of steps before turning 180
deg
        self.counter = 0        # index for counting steps

    def move(self):
        self.fd(self.stepsize)
        if self.counter >= self.steps:
            self.rt(180)
            self.counter = 0
        else:
            self.counter += 1

def main():
    s = Screen()
    s.clear()
    s.tracer(16, 0)
    b1 = Ball()

    i = 0
    t0 = time.time()
    while True:
        b1.move()
        i += 1
        if i > 2000:
            print(time.time() - t0)     # reports time span of the
interval
            i = 0
            t0 = time.time()

if __name__ == "__main__":
    main()
    mainloop()

A sample output to show the lengthening of the interval:

0.5490000247955322
0.625999927520752
0.7360000610351562
0.8619999885559082
0.9549999237060547
1.0649998188018799
1.2220001220703125
1.4100000858306885
1.3619999885559082
1.56600022315979
1.942000150680542
1.816999912261963
1.8640000820159912
2.113999843597412
2.0209999084472656
2.2710001468658447
2.254999876022339
2.3500001430511475
2.3959999084472656
2.50600004196167
2.5850000381469727
2.7260000705718994
2.803999900817871
2.9600000381469727
3.055000066757202
3.0859999656677246
3.2890000343322754
3.3519999980926514
3.4609999656677246
3.6029999256134033
3.634000062942505
3.758999824523926
3.883999824523926
4.134999990463257
...

Did I do something wrong?

Thank you very much for your time.

Best Regards,

EC


[toc] | [next] | [standalone]


#9927

FromTerry Reedy <tjreedy@udel.edu>
Date2011-07-19 22:29 -0400
Message-ID<mailman.1275.1311129011.1164.python-list@python.org>
In reply to#9921
On 7/19/2011 6:02 PM, EricC wrote:
> Hi,
>
> I am a newbie - I have been teaching myself Python 3 since a few
> months ago. My “self assignments” include some purely for fun. Among
> them was using the turtle module to have multiple turtles running
> around on the screen.
>
> Recently one such fun turtle “project” showed strange behavior that I
> cannot understand – while I achieved my goals (multiple turtles
> oscillate along random straight lines while changing colors), there
> was a steady slowing down of turtles as time goes. Actually they
> became so slow it is not even fun to look at.

There is a bug issue on the tracker that may be related to this. 
Unfortunately, the reviser of the turtle module is not actively 
maintaining it any more, though this might be an underlying tkinter or 
tk issue. Probably something is not being deleted that should be, or you 
are simply overloading the canvas memory and re-compute loop.

I have not specifically looked at your code.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web