Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turtle module crashes python #51323

Closed
terryjreedy opened this issue Oct 6, 2009 · 8 comments
Closed

Turtle module crashes python #51323

terryjreedy opened this issue Oct 6, 2009 · 8 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 7074
Nosy @loewis, @terryjreedy, @abalkin, @willingc
Superseder
  • bpo-11029: Crash, 2.7.1, Tkinter and threads and line drawing
  • Files
  • turtlecrash.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-05-29.07:08:10.535>
    created_at = <Date 2009-10-06.23:39:18.526>
    labels = ['type-bug', 'library']
    title = 'Turtle module crashes python'
    updated_at = <Date 2017-05-29.07:08:10.534>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2017-05-29.07:08:10.534>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-05-29.07:08:10.535>
    closer = 'terry.reedy'
    components = ['Library (Lib)']
    creation = <Date 2009-10-06.23:39:18.526>
    creator = 'terry.reedy'
    dependencies = []
    files = ['15060']
    hgrepos = []
    issue_num = 7074
    keywords = []
    message_count = 8.0
    messages = ['93669', '93670', '127682', '127684', '127971', '183771', '294670', '294676']
    nosy_count = 5.0
    nosy_names = ['loewis', 'terry.reedy', 'belopolsky', 'gregorlingl', 'willingc']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = '11029'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7074'
    versions = ['Python 3.2', 'Python 3.3']

    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Oct 6, 2009
    @terryjreedy
    Copy link
    Member Author

    resubmitting file

    @abalkin
    Copy link
    Member

    abalkin commented Feb 1, 2011

    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

    @abalkin abalkin added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 1, 2011
    @abalkin
    Copy link
    Member

    abalkin commented Feb 1, 2011

    This looks like a duplicate of bpo-11029. It is not safe to call graphic primitives in event callbacks. A workaround is described at <http://effbot.org/zone/tkinter-threads.htm\>.

    @abalkin abalkin closed this as completed Feb 1, 2011
    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy reopened this Feb 5, 2011
    @terryjreedy
    Copy link
    Member Author

    "It is not safe to call graphic primitives in event callbacks."
    Martin, do you agree that this is (or should be) the case?

    @willingc
    Copy link
    Contributor

    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.

    @terryjreedy
    Copy link
    Member Author

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants