Skip to content

Commit 5072535

Browse files
Reinit class variable _RUNNING
Initialising the class variable at the end of the object initialisation method. This will help to run this library smoothly in use cases such as in notebooks or GUI or other cell based or multiple turtle object instance execution. Otherwise it will raise Terminator error every second time. Will solve problems highlighted repeatedly in these stack overflow posts (With 1000s of views, current suggestions are some non-elegant workarounds such as importlib.reload(turtle) or or try-except and initializing again in the except as the _RUNNING becomes false at the end of last run or manually setting the _RUNNING flag). Logical to turn this to True after the initialization rather than during terminator exception. Change tested extensively and no issues found in any of the turtle-demo examples, notebooks or usual self-contained single instance execution. https://stackoverflow.com/questions/45534458/python-turtle-terminator-even-after-using-exitonclick https://stackoverflow.com/questions/34956937/weird-terminator-error-when-running-python-3-turtle-in-os-x https://stackoverflow.com/questions/70252586/turtle-module-for-langtons-ant-in-python-giving-me-raise-terminator-turtle-ter https://stackoverflow.com/questions/58078376/a-function-i-created-can-only-be-called-once-second-time-it-shows-an-error https://stackoverflow.com/questions/54198108/how-can-i-close-a-window-after-using-turtle https://stackoverflow.com/questions/67734319/running-turtle-multiple-times-but-receiving-a-terminator-error-after-the-first-r https://stackoverflow.com/questions/43294665/turtle-done-not-working-in-spyder https://stackoverflow.com/questions/50438762/python-turtle-window-crashes-every-2nd-time-running https://stackoverflow.com/questions/41644324/how-to-close-python-turtle-properly https://stackoverflow.com/questions/41548813/using-turtle-module-exitonclick/70552164 https://stackoverflow.com/questions/66750634/why-do-i-get-a-terminator-error-when-i-run-this-program https://stackoverflow.com/questions/65546812/python-turtle-terminator https://stackoverflow.com/questions/61963565/why-do-i-keep-getting-a-terminator-error-for-python-turtle
1 parent 549e628 commit 5072535

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/turtle.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,13 @@ def __init__(self, cv, mode=_CFG["mode"],
10021002
rootwindow = cv.winfo_toplevel()
10031003
rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
10041004
rootwindow.call('wm', 'attributes', '.', '-topmost', '0')
1005-
1005+
1006+
# The class variable _RUNNING being persistent once this module is imported, this should be made True when the next object is created.
1007+
# This is particularly needed for running in notebooks or GUI application but does not affect the usual self-contained single instance execution
1008+
# nor any of the turtle-demos
1009+
1010+
TurtleScreen._RUNNING = True
1011+
10061012
def clear(self):
10071013
"""Delete all drawings and all turtles from the TurtleScreen.
10081014

0 commit comments

Comments
 (0)