[Python-Dev] Re: threading issue: preventing starting twice
Russell E. Owen
rowen at cesmail.net
Thu Feb 26 15:17:17 EST 2004
In article <200402252140.i1PLeoT08847 at guido.python.org>,
Guido van Rossum <guido at python.org> wrote:
> > In the threading module, one must of course only start a thread once. I
> > have some questions about handling this gracefully.
> > First of all, the documentation only says it is an error to start a
> > thread more than once. It does not say which exception is raised. On my
> > system I find it is AssertionError. So...is that going to be true on all
> > systems? Is the test based on "assert", in which case it will go away
> > for optimized code (and then what happens)?
> Hey, it's open source! You can look for yourself. :-)
> Yes, the test is based on assert.
But if a feature is not documented, it could easily be changed in a
future release with no warning. Thus it would be a mistake to assume
that this error always raises AssertionError. (Also, since it is based
on assert, the error will not even be raised if enables the optimizer?).
> There is isRunning(). Isn't that enough? I realize it doesn't
> 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
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.
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.
More information about the Python-Dev