This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Turtle module crashes python
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder: Crash, 2.7.1, Tkinter and threads and line drawing
View: 11029
Assigned To: Nosy List: belopolsky, gregorlingl, loewis, terry.reedy, willingc
Priority: normal Keywords:

Created on 2009-10-06 23:39 by terry.reedy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
turtlecrash.py terry.reedy, 2009-10-06 23:41
Messages (8)
msg93669 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-10-06 23:38
Attached file run from IDLE edit window with 3.1, winxp works fine--
turtle moves in response to cursor keys-- if quit soon enough.
But after about 1000 key repeats, pythonw crashes with standard MSVC++
runtime error window, pythonw error window, and IDLE shell window
trackback ending with "RuntimeError: maximum recursion depth exceeded
while calling a Python object". The full traceback in appended to the file.

Disabling the undo buffer did not solve the problem.

Running the file from regular interpreter with
>>>exec(open(filename,'r').read())

gave essentially same result -- same traceback with slightly different
associated messages, so it is not an IDLE problem.

The demo/test at the bottem of turtle.py works fine -- but it does not
run as long.

I do not see the recursion, but calling the configuration merge with
every movement seems fishy.
msg93670 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-10-06 23:41
resubmitting file
msg127682 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-02-01 05:00
I can reproduce the crash on OSX.  After ~ 100 keystrokes, I get the following diagnostics:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/tkinter/__init__.py", line 1399, in __call__
    return self.func(*args)
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 701, in eventfun
    fun()
  File "turtlecrash.py", line 12, in klt
    def klt(): seth(180); fd(vel)
  File "<string>", line 1, in seth
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 1936, in setheading
    self._rotate(angle)
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 3277, in _rotate
    self._update()
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 2660, in _update
    self._update_data()
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 2651, in _update_data
    self._pencolor, self._pensize)
  File "/Users/sasha/Work/python-svn/py3k-commit/Lib/turtle.py", line 545, in _drawline
    self.cv.coords(lineitem, *cl)
  File "<string>", line 1, in coords
RuntimeError: maximum recursion depth exceeded
Fatal Python error: Cannot recover from stack overflow.
Abort trap
msg127684 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-02-01 05:14
This looks like a duplicate of issue11029.  It is not safe to call graphic primitives in event callbacks.  A workaround is described at <http://effbot.org/zone/tkinter-threads.htm>.
msg127971 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-02-05 02:32
This is not a duplicate because this issue is about the stdlib turtle module doing something wrong and needing to be fixed. Also, this issue does not involve threads, at least none that I starting.

"It is not safe to call graphic primitives in event callbacks."

This is a confusing statement. The tutorial at
http://www.tkdocs.com/tutorial/canvas.html
by an experienced tk developer (19 years) includes this:

def addLine(event):
    global lastx, lasty
    canvas.create_line((lastx, lasty, event.x, event.y))
    lastx, lasty = event.x, event.y

Is canvas.create_line a primitive or not?

At the very least, unless I missed something, some change to turtle doc is needed.
msg183771 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-03-08 23:25
"It is not safe to call graphic primitives in event callbacks."
Martin, do you agree that this is (or should be) the case?
msg294670 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2017-05-29 05:04
Ran the turtlecrash.py example with Python 3.6 on MacOS 10.12.4. I was unable to create a crash using keypresses. I recommend closing as 3.2 has reached EOL and 3.3 will reach EOL in less than 5 months. I'm going to change status to Pending and Resolution to out of date. I will close in 2 weeks if there is no further feedback on the issue. Thanks.
msg294676 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-05-29 07:08
I copied and pasted my code from turtlecrash.py into 3.7 editor, ran, and probably held key down for 3000 clicks, and it worked as it should.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51323
2017-05-29 07:08:10terry.reedysetstatus: pending -> closed

messages: + msg294676
2017-05-29 05:04:49willingcsetstatus: open -> pending

nosy: + willingc
messages: + msg294670

resolution: out of date
2013-03-08 23:25:41terry.reedysetnosy: + loewis
messages: + msg183771
2011-11-29 06:36:21ezio.melottisetversions: + Python 3.3, - Python 3.1
2011-02-05 02:32:21terry.reedysetstatus: closed -> open

messages: + msg127971
resolution: duplicate -> (no value)
nosy: terry.reedy, belopolsky, gregorlingl
2011-02-01 05:14:26belopolskysetstatus: open -> closed
nosy: terry.reedy, belopolsky, gregorlingl
messages: + msg127684

superseder: Crash, 2.7.1, Tkinter and threads and line drawing
resolution: duplicate
stage: resolved
2011-02-01 05:00:49belopolskysettype: crash -> behavior

messages: + msg127682
nosy: + belopolsky
2010-10-27 13:34:27belopolskysetnosy: + gregorlingl
2009-10-06 23:41:29terry.reedysetfiles: + turtlecrash.py

messages: + msg93670
2009-10-06 23:40:59terry.reedysetfiles: - turtlecrash.py
2009-10-06 23:39:19terry.reedycreate