[Python-ideas] Restartable Threads

Aahz aahz at pythoncraft.com
Mon Mar 3 01:33:50 CET 2008


On Sun, Mar 02, 2008, Gabriel Grant wrote:
> 
> Why is it that threads can't be restarted?

That's an interesting question.  Unfortunately, the best person to answer
it isn't on this list (Tim Peters).  Generally speaking, the standard
answer is to have a worker thread that uses a Queue in a loop.

> So this _seems_ to work, but I have to admit, I'm somewhat afraid to
> use it. I can't help but wonder: is it safe, or is it tempting the
> Gods of parallelism to inflict sudden, multi-threaded death?

If I had to guess, I think it's just adding an unnecessary layer of
complexity to the existing Thread class.  Moreover, the existing
implementation prevents the following code:

t.start()
t.run()
t.run()

which IMO definitely should be a bug.  If you want to try creating a
patch that that adds a t.restart() method, I think it certainly wouldn't
hurt anything and would be a good way of getting feedback.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson



More information about the Python-ideas mailing list