The is_alive() method in threading module, is described as this:
This method returns True just before the run() method starts until just after the run() method terminates.
Doesn’t that mean is_alive return True before the run() method starts? I am not a native speaker, so I am not sure whether it is indeed worded in a confusing way or just I didn’t quite understand it.
It says “just before” and “just after”. In colloquial English this
implies as close to the start of run() as possible and as close to the
end as possible…
I expect that the module endeavours to ensure that is_alive() returns True for the entire period when run() is running, but as close to
that as possible. Consider how this is probably implemented
(pseudocode):
I agree that the wording in the documentation could be better, but you got it right:
Yes. When the docs say that is_alive() returns True just beforerun() starts, it means that Python will first set a flag to indicate that the thread is alive, and then start executing the run() method. That is, there is a brief period of time in which the flag has been set, but the run() method has not yet been called.
The purpose is to tell you that the thread is alive, run() may or may not be running. At a high level you can think of the run() being the same as the thread running.