Title: Catch turtle.Terminator exceptions in turtledemo
Type: behavior Stage: resolved
Components: Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: python-dev, terry.reedy
Priority: normal Keywords:

Created on 2014-06-22 04:15 by terry.reedy, last changed 2014-06-22 06:27 by terry.reedy. This issue is now closed.

Messages (4)
msg221215 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-22 04:15
When a turtle update operation cannot finish because the underlying canvas has been cleared (when the STOP button is pushed), turtle.Terminator is raised. When turtledemo runs the main function of a demo, it catches any Termininator raised before main returns. 

However, special demos leave an event loop running after main returns.  If the demo is free running, as with clock and minimal_hanoi, clicking STOP causes such exceptions.  (This is not be a problem with paint as updates only happen in response to mouse events on the canvas and complete before a user could move the mouse to the STOP button.)

This is the clock trackback, with common file prefix removed:
  \tkinter\", line 1487, in __call__
    return self.func(*args)
  \tkinter\", line 532, in callit
  \turtledemo\", line 116, in tick
  \", line 1935, in setheading
  \", line 3277, in _rotate
  \", line 2659, in _update
  \", line 2645, in _update_data
  \", line 1291, in _incrementudc
    raise Terminator

The hanoi traceback starts differently:
  \tkinter\", line 1487, in __call__
    return self.func(*args)
  \", line 686, in eventfun
  \turtledemo\", line 53, in play
    hanoi(6, t1, t2, t3)
  ...<5 recursive calls deleted>
  \turtledemo\", line 36, in push
  \turtledemo\", line 36, in push
  \", line 1807, in setx
    self._goto(Vec2D(x, self._position[1]))
  \", line 3178, in _goto
  <last 3 lines as above>

These exceptions and tracebacks do not stop the master demo window, but are printed to the console (python -m turtledemo) or Idle Shell (open in editor, run). They are ugly, might unnecessarily alarm a naive user, or falsely teach that tracebacks are to be ignored.

In the patch to clock.tick, I put try: at the top, to be safe, although just before the update of the second hand might be good enough.
msg221216 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-06-22 05:21
New changeset a43d03cdf38b by Terry Jan Reedy in branch '2.7':
Issue #21823: Catch turtle.Terminator exceptions in turtledemo.

New changeset 1ae2382417dc by Terry Jan Reedy in branch '3.4':
Issue #21823: Catch turtle.Terminator exceptions in turtledemo.
msg221217 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-22 05:24
In 2.7, the exception in tick occurred at tracer(False), so I moved try: up in all patches.
msg221221 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-22 06:27
Since hanoi do not have user interaction, once started, it does not need to be 'special'. Like planets_and_moon, it could run until done and then return 'Done'.
Date User Action Args
2014-06-24 23:11:34terry.reedylinkissue14117 dependencies
2014-06-22 06:27:42terry.reedysetmessages: + msg221221
2014-06-22 06:02:29terry.reedylinkissue17172 dependencies
2014-06-22 05:24:00terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg221217

stage: needs patch -> resolved
2014-06-22 05:21:13python-devsetnosy: + python-dev
messages: + msg221216
2014-06-22 04:15:08terry.reedycreate