7

When I run a turtle graphics cell and draw some stuff its alright, but if I close the window and run the cell again I get a weird error called Terminator, and I have to restart the kernel in order to be able to run the cell again. It also happens to me if I try to run 2 different turtle graphics cells( the 2 cells draw different stuff and are well coded) consecutively. If I run one of them, then I restart the kernel, and run the other one, no error happens, but having to restart the kernel all the time isn't good and makes me upset. This only happens to me with my new macbook, with my PC Windows everything's fine and I can run consecutively and repetitively turtle graphics cells and the only think I need to do is closing the current turtle window to run the other.

import turtle
window = turtle.Screen()
t = turtle.Turtle()

t.forward(50)
turtle.mainloop()

If I run this code one time it's alright.But if I close the turtle window and run it again without restarting the kernel before, I get this error:

--------------------------------------------------------------------------
Terminator                                Traceback (most recent call last)
<ipython-input-2-48bfc10d8dfd> in <module>()
      2 
      3 window = turtle.Screen()
----> 4 t = turtle.Turtle()
      5 
      6 t.forward(50)

/Users/marti/anaconda/lib/python3.5/turtle.py in __init__(self, shape,   undobuffersize, visible)
   3814                            shape=shape,
   3815                            undobuffersize=undobuffersize,
-> 3816                            visible=visible)
   3817 
   3818 Pen = Turtle

/Users/marti/anaconda/lib/python3.5/turtle.py in __init__(self, canvas,     shape, undobuffersize, visible)
   2555         self._undobuffersize = undobuffersize
   2556         self.undobuffer = Tbuffer(undobuffersize)
-> 2557         self._update()
   2558 
   2559     def reset(self):

/Users/marti/anaconda/lib/python3.5/turtle.py in _update(self)
   2658             return
   2659         elif screen._tracing == 1:
-> 2660             self._update_data()
   2661             self._drawturtle()
   2662             screen._update()                  #     TurtleScreenBase

/Users/marti/anaconda/lib/python3.5/turtle.py in _update_data(self)
   2644 
   2645     def _update_data(self):
-> 2646         self.screen._incrementudc()
   2647         if self.screen._updatecounter != 0:
   2648             return

/Users/marti/anaconda/lib/python3.5/turtle.py in _incrementudc(self)
   1290         if not TurtleScreen._RUNNING:
   1291             TurtleScreen._RUNNING = True
-> 1292             raise Terminator
   1293         if self._tracing > 0:
   1294             self._updatecounter += 1

Terminator: 

I have no idea of why Im getting this error and found poor information about it on internet myself.The same error happens if I have different turtle cells and run one before the other. The only thing that I found was in the help() command tipping turtle on the finder.Thats what I found here about terminator:

CLASSES
    builtins.Exception(builtins.BaseException)
        Terminator

class Terminator(builtins.Exception)
     |  Will be raised in TurtleScreen.update, if _RUNNING becomes False.
     |  
     |  This stops execution of a turtle graphics script.
     |  Main purpose: use in the Demo-Viewer turtle.Demo.py.
     |  
     |  Method resolution order:
     |      Terminator
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |  
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  

I'm a bit newbie on programming and this error is upsetting me a lot.I do wish somebody could help me. Also maybe could help to solve the problem the fact that when I run a turtle and then I close the window in a right way, like using mainloop(), the turtle graphics window seems to be closed but actually I keep seeing it on the dock bar, like if it was minimized or if it was already running, and then when I run another turtle graphics window maybe the fact that the old one keeps opened in some kind of weird way affects the new one and I get this Terminator error.

Borrell
  • 71
  • 1
  • 4
  • I have no experience with ipython, anaconda, or osx and I do not understand what *you* mean by 'turtle cell' or 'restart the kernal'. If you run `python myturtle.py` at the command line, close the window, and run again, there should be no problem. Try this to make sure. In https://hg.python.org/cpython/rev/1ae2382417dc/, I patched turtle files to catch Terminator that arose from the special circumstance that the turtle program was stopped by the external demo programs. It may be that Anaconda on OSX is not properly set up to run turtle programs. Try running from IDLE instead. – Terry Jan Reedy Jan 23 '16 at 03:15
  • 1
    Thanks for the answer Terry. With turtle cell I mean a code cell in ipython notebook in which I write turtle graphics code that makes a turtle or multiple turtles draw something. With kernel I mean the stuff that makes ipython notebook work, kind of the core of the program or something. I tried to run `python myturtle.py` but it says that there is no such file or directory. – Borrell Jan 23 '16 at 04:23
  • 1
    The stuff of the python.org website I don't know how to manage it and it seems that in IDLE turtle works but my objective was running it on ipython notebook because its easier for me to manipulate it and learn it. Maybe you are right and anaconda on OS X is not properly set up to run turtle programs... or maybe I have anaconda missinstaled or something weird. Thank you anyway! – Borrell Jan 23 '16 at 04:23
  • 1
    The Terminator docstring, printed with help(), is a bit confusing. I don't know if turtle has ever been a package, but it is not in either 2.7 or 3.x. In 3.x, the 'demo viewer' is in turtledemo/__main__.py. The viewer sets `_RUNNING = True` and calls `somedemo.main()`. The Stop button sets `_RUNNING = False`. `Terminator` is caught either in `somedemo` or the viewer itself. I looked at the turtle code and my hypothesis is that Anaconda is running turtle in a supervised manner such that turtle.py is not re-read from scratch and _RUNNING is not reset to True. – Terry Jan Reedy Jan 23 '16 at 04:43
  • You have to either replace `myturtle.py` with the full path or change to the director that contains it. – Terry Jan Reedy Jan 23 '16 at 04:44
  • But how can I do that if I can't find this `myturtle.py ` file anywhere? – Borrell Jan 23 '16 at 05:40

2 Answers2

2

May be these small quack code will do. After module import code. call these line turtle.clear() After drawing completion with turtle then, go to next cell and run turtle.bye()

It is a quick fix.

Best is call exitonclick() method on the turtle window/canvas after turtle finish drawing. e.g

turtle_window = turtle.Screen() 
........Draw something 
turtle_window.exitonclick()
0

This is because the turtle module (most reference implementations as of today) uses a class variable called _RUNNING. This becomes false during the exitonclick() method.

Changing your code to below should help to run in the way you want:

import turtle
turtle.TurtleScreen._RUNNING=True
window = turtle.Screen()
t = turtle.Turtle()

t.forward(50)
turtle.mainloop()
William
  • 464
  • 2
  • 16