Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird Terminator error when running Python 3 Turtle in OS X

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.

like image 583
Borrell Avatar asked Jan 22 '16 22:01

Borrell


1 Answers

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()
like image 67
Prem Bikram Limbu Avatar answered Nov 15 '22 08:11

Prem Bikram Limbu