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: _tkinter.TclError: invalid command name ".10170160" #50888

Closed
srid mannequin opened this issue Aug 4, 2009 · 12 comments
Closed

turtle: _tkinter.TclError: invalid command name ".10170160" #50888

srid mannequin opened this issue Aug 4, 2009 · 12 comments
Assignees
Labels
stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@srid
Copy link
Mannequin

srid mannequin commented Aug 4, 2009

BPO 6639
Nosy @terryjreedy, @abalkin, @ned-deily, @asvetlov, @serhiy-storchaka
Files
  • turtle_bug.patch
  • turtle_crash.patch
  • turtledemo_destroy.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-02-22.15:30:30.194>
    created_at = <Date 2009-08-04.00:09:24.006>
    labels = ['expert-tkinter', 'type-bug', 'library']
    title = 'turtle: _tkinter.TclError: invalid command name ".10170160"'
    updated_at = <Date 2015-02-22.15:30:30.194>
    user = 'https://bugs.python.org/srid'

    bugs.python.org fields:

    activity = <Date 2015-02-22.15:30:30.194>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-02-22.15:30:30.194>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'Tkinter']
    creation = <Date 2009-08-04.00:09:24.006>
    creator = 'srid'
    dependencies = []
    files = ['35384', '35462', '36531']
    hgrepos = []
    issue_num = 6639
    keywords = ['patch', 'needs review']
    message_count = 12.0
    messages = ['91248', '109949', '119414', '119711', '219013', '219248', '219643', '219644', '224328', '226346', '227393', '236410']
    nosy_count = 10.0
    nosy_names = ['terry.reedy', 'belopolsky', 'gregorlingl', 'ned.deily', 'asvetlov', 'srid', 'jesstess', 'python-dev', 'serhiy.storchaka', 'Lita.Cho']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6639'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @srid
    Copy link
    Mannequin Author

    srid mannequin commented Aug 4, 2009

    I tried the following turtle program; it was taking some time to
    draw .. so I pressed C-c after which I saw the exception traceback.

    cat play.py
    from turtle import *

    def f(length, depth):
       if depth == 0:
         forward(length)
       else:
         f(length/3, depth-1)
         right(60)
         f(length/3, depth-1)
         left(120)
         f(length/3, depth-1)
         right(60)
         f(length/3, depth-1)
    
    f(500, 4)
    > python play.py
    Traceback (most recent call last):
      File "/Users/sridharr/as/pypm/bin/python", line 41, in <module>
        execfile(sys.argv[0])
      File "play.py", line 15, in <module>
        f(500, 4)
      File "play.py", line 11, in f
        f(length/3, depth-1)
      File "play.py", line 7, in f
        f(length/3, depth-1)
      File "play.py", line 9, in f
        f(length/3, depth-1)
      File "play.py", line 10, in f
        left(120)
      File "<string>", line 1, in left
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/turtle.py", line 1612, in left
        self._rotate(angle)
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/turtle.py", line 3107, in _rotate
        self._update()
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/turtle.py", line 2562, in _update
        self._update_data()
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/turtle.py", line 2553, in _update_data
        self._pencolor, self._pensize)
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/turtle.py", line 569, in _drawline
        self.cv.coords(lineitem, *cl)
      File "<string>", line 1, in coords
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
    lib-tk/Tkinter.py", line 2136, in coords
        self.tk.call((self._w, 'coords') + args)))
    _tkinter.TclError: invalid command name ".10170160"
    >

    @srid srid mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error topic-tkinter labels Aug 4, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 11, 2010

    Anyone with turtle/Tkinter knowledge who can shed some light on this?

    @abalkin
    Copy link
    Member

    abalkin commented Oct 23, 2010

    I have come across the same bug. To reproduce, run Demo/turtle/tdemo_round_dance.py and kill the Tk window before the "dance" stops.

    The mysterious command name ".10170160" is simply the generated name for the canvas widget - '.' + repr(id(self)). See BaseWidget.__init__ in tkinter.

    @abalkin
    Copy link
    Member

    abalkin commented Oct 27, 2010

    Same error occurs when the python -m turtle demo is interrupted by closing the window. I think the correct fix is to exit when the window is closed, but I cannot figure out the best way to achieve that. This probably should be done at the application/test level.

    @LitaCho
    Copy link
    Mannequin

    LitaCho mannequin commented May 23, 2014

    I was looking at this more, and from my understanding, the turtle code is continuing to run even when the TK window is destroyed. Thus the crash.

    It looks like the drawing functions are being made on the fly with the following method:

    for methodname in _tg_turtle_functions:
        pl1, pl2 = getmethparlist(eval('Turtle.' + methodname))
        if pl1 == "":
            print(">>>>>>", pl1, pl2)
            continue
        defstr = ("def %(key)s%(pl1)s: return _getpen().%(key)s%(pl2)s" %
                                       {'key':methodname, 'pl1':pl1, 'pl2':pl2})
        exec(defstr)
        eval(methodname).__doc__ = _turtle_docrevise(eval('Turtle.'+methodname).__doc__)

    So while all the methods are being generated, I am going to add in a check to see if the window was destroyed before running the pen code. If it was, then I exit gratefully. The check will be duplicated for each pen method, but I feel it is the best way to contain the check within the turtle.py module. The other option would be to make the user check for it, which is not a good option.

    @LitaCho
    Copy link
    Mannequin

    LitaCho mannequin commented May 28, 2014

    So I have a patch that fixes the original problem, but doesn't fix the crash with the tdemo_round_dance.py. However, I was wondering why TurtleScreen._RUNNING = True in the _destroy method. Can anyone shed some light on this? Here is the current state of my patch.

    @LitaCho
    Copy link
    Mannequin

    LitaCho mannequin commented Jun 2, 2014

    So it looks like the bug fix was really simple. I just needed to set TurtleScreen._RUNNING to True when the screen object tries to get destroyed.

    @LitaCho
    Copy link
    Mannequin

    LitaCho mannequin commented Jun 2, 2014

    Oops, pressed submit too soon.

    Now the programs raise a Terminator exception rather than a TclError, which I think is correct because the programs are calling Turtle methods when the TurtleScreen had been destroyed.

    I wasn't sure if it was better to return None rather than raise an exception, but I think raising exception is correct, as these programs are not calling mainloop to handle event loops. So when the user closes the window, round_dance.py should handle that.

    @LitaCho
    Copy link
    Mannequin

    LitaCho mannequin commented Jul 30, 2014

    I can make it worth such that it doesn't raise a Terminator error. This works great when working with Turtle on the command line. I basically check if the root exists for all Tk canvas calls.

    If it got destroyed, then it just returns. However, if you run the following recursive code, it will just keep popping up a window forever unless you Ctrl+C out of the program. So that is not going to work. I still believe raising an error is the proper approach.

    @serhiy-storchaka
    Copy link
    Member

    Here is more complete patch.

    @serhiy-storchaka
    Copy link
    Member

    Any feedback?

    @serhiy-storchaka serhiy-storchaka self-assigned this Feb 15, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 22, 2015

    New changeset 15dd9d6cc632 by Serhiy Storchaka in branch '2.7':
    Issue bpo-6639: Module-level turtle functions no longer raise TclError after
    https://hg.python.org/cpython/rev/15dd9d6cc632

    New changeset 1628484c9408 by Serhiy Storchaka in branch '3.4':
    Issue bpo-6639: Module-level turtle functions no longer raise TclError after
    https://hg.python.org/cpython/rev/1628484c9408

    New changeset d8e494986caf by Serhiy Storchaka in branch 'default':
    Issue bpo-6639: Module-level turtle functions no longer raise TclError after
    https://hg.python.org/cpython/rev/d8e494986caf

    @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 topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants