Title: Turtle Shutdown Problem(s)
Type: behavior Stage: resolved
Components: macOS, Tkinter Versions: Python 3.7
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: bmoth, eric.smith, gregorlingl, ned.deily, ronaldoussoren, willingc, xtreak
Priority: normal Keywords:

Created on 2018-11-10 19:39 by bmoth, last changed 2018-11-12 04:25 by bmoth. This issue is now closed.

File name Uploaded Description Edit
turtle shutdown problem.txt bmoth, 2018-11-10 19:39 shell output from free python games bmoth, 2018-11-11 06:02 bmoth, 2018-11-11 06:02 alt-q once.jpg bmoth, 2018-11-11 16:41 screen output after alt-Q pressed once during execution bmoth, 2018-11-11 16:50 rewrite of to eliminate possible problems bmoth, 2018-11-12 04:18 debug version of submitted earlier bmoth, 2018-11-12 04:25 debugged version of (-- just drag to launcher w/out -i)
Messages (17)
msg329640 - (view) Author: bob moth (bmoth) Date: 2018-11-10 19:39
Running from the Free Python Games requires
alt-Q twice, and the GUI keeps running after System.exit.

Running, (which is my clone, and I will happily 
share it if you want a great stress tester that gobbles
100% of a CPU core for as long as you want,) doesn't
respond to alt-Q and requires a force quit.
msg329647 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-11-10 22:41
Please create a small program that reproduces the problem. You should strip out everything that isn't needed. There's no way we can guess the problem without seeing the code.
msg329648 - (view) Author: bob moth (bmoth) Date: 2018-11-10 23:08
send to you?


> On Nov 10, 2018, at 14:41, Eric V. Smith <> wrote:
> Eric V. Smith <> added the comment:
> Please create a small program that reproduces the problem. You should strip out everything that isn't needed. There's no way we can guess the problem without seeing the code.
> ----------
> nosy: +eric.smith
> _______________________________________
> Python tracker <>
> <>
> _______________________________________
msg329649 - (view) Author: bob moth (bmoth) Date: 2018-11-10 23:23
Here is the source, just simply Turtles... <>

Attached and

I don't know what cause the problem. I suspect
there is more of a problem than just alt-Q 

> On Nov 10, 2018, at 15:08, Bob Moth <> wrote:
> send to you?
> .
>> On Nov 10, 2018, at 14:41, Eric V. Smith <> wrote:
>> Eric V. Smith <> added the comment:
>> Please create a small program that reproduces the problem. You should strip out everything that isn't needed. There's no way we can guess the problem without seeing the code.
>> ----------
>> nosy: +eric.smith
>> _______________________________________
>> Python tracker <>
>> <>
>> _______________________________________
msg329663 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-11-11 05:19
Please quote only the relevant parts of the original email while replying from email since it duplicates the content and makes your reply hard to read. Also I think the bug tracker doesn't support attachments from email so please attach them here from the UI.

msg329676 - (view) Author: bob moth (bmoth) Date: 2018-11-11 16:41
looking at the screen snapshot ' alt-q once.jpg' -- the
turtle code keeps running even though System.exit has been completed,
and notice the traceback display in the shell caused by the alt-Q.

a second press of alt-Q terminates the shell and the turtle code.
msg329677 - (view) Author: bob moth (bmoth) Date: 2018-11-11 16:50
I rewrote the using a class in order to eliminate global
variable declarations, and some other things, such as bringing
freegames.util#square() instream to be independent of freegames,
carefully accounting for every pixel output, etc. 

Works a little better but alt-Q has no effect whatsoever and 
it is necessary to Force Quit (mac terminology) or to switch to
the shell window and quit that first. 

Once this bug is fixed, wherever that might be, you might look into
using as an turtle example -- with whatever changes you
like -- because it is interesting to use and it exercises the turtle
and tkinter very strenuously. (just leave my name off it...)

Thanks for your hard work.
msg329685 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-11 20:36
There seem to be at least two problems here.

One, you say that running the unmodified requires two Quit keyboard shortcuts (usually CMD-Q).  From the shell output you give, that problem is most likely due to the use of -i with python:

'/usr/local/bin/python3' -d -i  '/Users/user2/Downloads/'

-i means that the interpreter should enter its interactive mode after the script exists.  With tkinter-based graphics apps like turtle, you probably do not want to do that as it will inhibit the normal Tk shutdown of the app.

Without -i, the unmodified terminates fine for me.

Secondly, your modified does not terminate with a Quit even when running without -i.  (Note that it *does* quit if you select Close from the applications's File menu or if you click on the red close button on the open window.)  From a quick comparison of the unmodified Pygames versus your modified version, it seems you have changed the order of operations in such a way that the sequence of turtle operations has changed and likely the underlying tkinter event loop is not being called properly thus either ignoring or suppressing the effect of the Quit keyboard shortcut.  Suggest you revise your program to follow the sequence of turtle calls that the original does and be careful if you wish to introduce changes in that.  If you do find what appears to be a bug in turtle or elsewhere in Python, feel free to re-open this with an example and an explanation.  Good luck!
msg329688 - (view) Author: bob moth (bmoth) Date: 2018-11-11 21:02
hi - i do not use ā€˜iā€™...just drag to

and sequence of commands is
a good tip but smells like some
kind of bug to me if the commands
follow written rules. 

thanks for looking -

msg329689 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-11 21:36
Alas, the Launcher app can be problematic and doesn't get much love.  If you open the Launcher app's Preferences, you'll probably see that the "Interactive mode after acript" option is ticked.  Either unselect it or, if you feel comfortable using a Terminal window, just launch Python directly from a terminal shell:

python3 ~/Downloads/
msg329690 - (view) Author: bob moth (bmoth) Date: 2018-11-11 22:01
OK, thanks. The generated launcher shell command generated
includes '-d -i' flags...

so I tried running without those and voila, terminates
normally. Yay. :-)

2nd, I reviewed the order of commands and I saw that and (the +1 version) did not have a
'done()' or 'mainloop()' as the last line of the program.
I added those, to no effect. Does nothing I can see.
The other turtle commands appear to me to be "ok",
given that the algorithm is different. For example,
clear() used to be done every loop -- to erase the
turtle tracks -- but that is now done just at the start
because only changed cells are updated, and 
new life/new dead are just updated. 

So, 50% solved. It is an interesting problem because
*my* code seems to be working and *python* does
not appear to be working right. 

Thanks for the help. I might try pygame for a gui
instead...this is getting weird.
msg329691 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-11 22:11
You may might try asking on the freegames issue tracker or, better, on a more general support forum like Stackoverflow or Python-list. Because of the volume of issues reported here (and we are all volunteers), we really can't spend a lot of time helping debug individual programs.  Sorry!
msg329700 - (view) Author: bob moth (bmoth) Date: 2018-11-12 00:18
Thanks. I appreciate the time and effort. 

But I disagree with the characterization of
this problem as 'Resolved'. Turtle is
supposed to be simple enough for children yet 
no one can fix simple turtle code and stop
an endless loop? 

What is the rush to close issues?
msg329705 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-12 00:36
Sorry, there isn't a particular rush to close issues as some of them stay open for years. And that's not good for anyone.  "resolved" on the issue tracking does not necessarily mean a problem is resolved to everyone's satisfaction, it just means that it is no longer active in our backlog (which currently numbers over 6000).  I don't claim to be a turtle expert but the bit of time I spent looking into this issue and my years of triaging Python issues lead me to conclude this is almost certainly a problem with your program and not with Python itself.  We could leave it open but the chances that any other core developer would spend time looking further at it are slim.  That's why I suggested asking on user forums where you are much more likely to get useful and more rapid feedback.  And as I earlier suggested, if it *does* turn out to be a demonstrable problem with turtle or elsewhere in Python, you can easily reopen the issue and we can go from there. I hope that makes some sense!
msg329706 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-11-12 00:39
And, by the way, if it turns out that the problem could have been avoided by better documentation, another option is to re-open the issue with suggested doc changes.  Patches welcome!
msg329708 - (view) Author: bob moth (bmoth) Date: 2018-11-12 04:18
Apparently the draw() function must call itself via ontimer.

That is not in the docs. But 56 variations later...I just copied
Grant Jenks. Apparently he knows what's what.

And done() must be the last line.

If first omitted, only one draw loop executed, but it quits itself.
With done(), it loops via ontimer().

def draw():
    ontimer(draw, LOOP_TIMER)
setup(BOARD_SIDE, BOARD_SIDE, None, None)

So now alt-Q works in attached.
msg329709 - (view) Author: bob moth (bmoth) Date: 2018-11-12 04:25
Here is a debugged version of mylife, which cloned to
use a class for turtle-ing. Note the difficulties at the
end of the code -- ontimer(fun, delay) calls for a zero arg
function, so draw() cannot be inside the class. Greatly annoying.
But now we know. is a suitable example, I think. If cleaned up to
standards. I noticed there is a curses example, which
is very interesting and fun, but is more fun...and
it has 2 different board topologies! And
it would make a very good test program. Note that it sets
the random seed which establishes the Cell patterns, so a
test ought to be repeatable, at least on a given machine.
I plan to use instead of a space heater this winter :)
Date User Action Args
2018-11-12 04:25:15bmothsetfiles: +

messages: + msg329709
2018-11-12 04:18:30bmothsetfiles: +

messages: + msg329708
2018-11-12 00:39:56ned.deilysetmessages: + msg329706
2018-11-12 00:36:21ned.deilysetmessages: + msg329705
2018-11-12 00:18:01bmothsetmessages: + msg329700
2018-11-11 22:11:14ned.deilysetmessages: + msg329691
2018-11-11 22:01:16bmothsetmessages: + msg329690
2018-11-11 21:36:24ned.deilysetmessages: + msg329689
2018-11-11 21:02:33bmothsetmessages: + msg329688
2018-11-11 20:36:41ned.deilysetstatus: open -> closed
resolution: works for me
messages: + msg329685

stage: resolved
2018-11-11 16:50:24bmothsetfiles: +

messages: + msg329677
2018-11-11 16:41:41bmothsetfiles: + alt-q once.jpg

messages: + msg329676
2018-11-11 06:02:55bmothsetfiles: +
2018-11-11 06:02:35bmothsetfiles: +
2018-11-11 05:19:11xtreaksetnosy: + xtreak
messages: + msg329663
2018-11-10 23:23:45bmothsetmessages: + msg329649
2018-11-10 23:08:33bmothsetmessages: + msg329648
2018-11-10 22:41:19eric.smithsetnosy: + eric.smith
messages: + msg329647
2018-11-10 19:49:01ned.deilysetnosy: + gregorlingl, willingc
2018-11-10 19:39:52bmothcreate