[Python-Dev] Re: threading issue: preventing starting twice
Guido van Rossum
guido at python.org
Thu Feb 26 15:34:12 EST 2004
> > There is isRunning(). Isn't that enough? I realize it doesn't
[I meant isAlive()]
> > distinguish between "not yet running" and "no longer running", but
> > your application state should be enough to distinguish between the
> > two, right?
> I am trying to determine the state of a thread, and in particular
> determine if it's safe to try to start it. Thus isRunning is explicitly
> not enough.
> The result is in my own code I end up writing a status layer around the
> thread, but I assume many other programmers have to do the same thing.
I don't know about that. I almost always create a thread and then
immediately start it, so I never have this problem. I assume most
other programmers do the same thing.
> It seems a rather roundabout way to do things when the threading Thread
> object ought to have a pretty good idea what state it is in.
I admit, the info is there, but not easily accessible. I copied the
Java Thread class, which has the same interface "deficiency". I'm not
totally against adding a way to determine a thread's state (with three
outcomes: initial, started, stopped) but I'm not quite sure that your
use case isn't the result of an awkward way of using threads, in which
case I don't want to encourage that. :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev