[Tutor] another question ( unrelated )

Luke Paireepinart rabidpoobear at gmail.com
Fri Jul 20 18:18:50 CEST 2007


shawn bright wrote:
> If i have a thread, of type threading.Thread
> that i initiate with an __init__
> in the
> def run(self):
>      while 1:
>           do some stuff
>
>
> is there a way i can stop this thread and restart this thread from 
> within itself ?
Speaking from a purely theoretical standpoint (in other words I don't 
know the answer to your question)
a thread can be thought of as a separate execution path.  If it's going 
along and executing stuff, and it reaches a point where
it needs to terminate itself, that means it is no longer executing, 
therefore it can't possibly restart itself.
Metaphor: If a wizard can cast Revive to bring people back to life, but 
he's dead, he can't revive himself because he can't cast spells anymore.

However, I think you could have it just do a sleep of some sort so that 
the CPU is delegated (relegated?) to the other threads mostly, until the 
sleep is up.
Or, if you didn't want a constant amount of time to be given up to the 
other threads, you'd have to communicate to the halted thread when it 
should resume.

Those are my thoughts on this, but as I said, I'm not sure and I could 
be wrong.
Why do you need to do this?
-Luke


More information about the Tutor mailing list