Issue 1702036: Make Turtle thread-safe so it does not crash (original) (raw)

Created on 2007-04-17 08:29 by korka, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg55062 - (view) Author: lomm (korka) Date: 2007-04-17 08:29
These are a few examples of errors during code-reentry in the turtle module: System tested: Windows XP sp2, Python 2.5 1. turtle.circle fails if the tkinter is closed while drawing. # Code example: import turtle turtle.circle(100) # close the tkinter window while the circle is drawing # will give an "invalid command name" exception 2. using multiple inheritance, it's possible to draw more than 1 turtle running around at a time. This works part of the time, but crashes python completely on occasions. # Code example: import turtle, random from threading import Thread class Ninja(Thread, turtle.Turtle): 'A ninja is a threaded turtle' def __init__(self): # constructors Thread.__init__(self) turtle.Turtle.__init__(self) # where will i go? self.Direction = random.randint(-180,180) def run(self): # that way! self.left(self.Direction) # march 'forward' for i in range(50): self.forward(16*random.random()) self.left(22 - 45*random.random()) ninjas = [] for i in range(3): ninjas.append(Ninja()) ninjas[-1].start()
msg55063 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2007-04-19 05:12
Does Turtle claim to be thread safe in the documentation? Should we explicitly state that Turtle is not thread safe? Should we also say, "don't close the turtle window while it is drawing"?
msg55064 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-04-19 06:58
As Josiah says, the current docs do not make any promises about thread-safety. So, this isn't a bug. That being said, it would be nice to offer a way to have multiple turtles running around under the control of different threads.
msg120464 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-05 02:08
I think threading is a red herring here. The issue is really a duplicate of #6639.
msg120465 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-05 02:19
On a closer look at the first post, I see that there are two parts to the issue. The first is indeed a duplicate of #6639, but the second is thread related. I am attaching the OP's code in a script file for convenience. Running ninja.py under python3 produces RuntimeError: main thread is not in main loop in every ninja thread. This looks like tkinter limitation, but I think it is possible to work around it in turtle, so this is a valid feature request. +1
msg224436 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-07-31 18:25
Hey! So I have been investigating this bug, but I wanted to know is the issue the fact that korka wants to create multiple turtles or do you really want to use multiple threads with Turtle? I feel like this crash is due to Tkinter not being thread safe and I am not sure how turtle can go about working around this other than creating a scheduler within turtle.
msg224437 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-07-31 18:32
I also want to note that you can create duplicate turtles by using clone, and I am not sure why you would use multiple inheritance to draw more than 1 turtle running around. I didn't think turtle was meant to be used this way. In order to draw multiple turtles, I would use the clone method. Is this to draw turtles running at the same time?
msg319746 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2018-06-16 15:08
Hi all, I'm triaging 'turtle' open issues. I'm going to close this issue with a resolution of not a Turtle bug. Thanks.
History
Date User Action Args
2022-04-11 14:56:23 admin set github: 44857
2018-06-16 15:08:18 willingc set status: open -> closednosy: + willingcmessages: + resolution: not a bugstage: test needed -> resolved
2014-07-31 18:32:04 Lita.Cho set messages: +
2014-07-31 18:25:46 Lita.Cho set messages: +
2014-07-22 03:05:16 rhettinger set priority: normal -> lowversions: + Python 3.5, - Python 3.2
2014-07-22 01:55:32 Lita.Cho set nosy: + jesstess
2014-07-21 20:37:24 BreamoreBoy set nosy: + Lita.Cho
2010-11-05 02:19:39 belopolsky set status: pending -> openmessages: +
2010-11-05 02:08:18 belopolsky set status: open -> pendingnosy: + belopolskymessages: + superseder: turtle: _tkinter.TclError: invalid command name ".10170160"
2010-10-27 13:35:41 belopolsky set nosy: + gregorlingl
2010-08-09 03:44:29 terry.reedy set title: Turtle isn't thread-safe (crashes) -> Make Turtle thread-safe so it does not crashversions: + Python 3.2, - Python 3.1, Python 2.7
2009-03-30 16:49:34 ajaksu2 set stage: test neededversions: + Python 3.1, Python 2.7, - Python 2.6
2007-04-17 08:29:04 korka create