Threading in python
Peter Hansen
peter at engcorp.com
Tue Dec 13 20:40:20 EST 2005
Carl J. Van Arsdall wrote:
> Hi everyone, I'm trying to use the threading module with python 2.2 and
> I have some questions regarding python's threading.
My answers are meant to supplement Aahz' from another reply.
> 3. Is there a way to which thread is running?
"A way to" what? "See"? There is the threading.currentThread() call,
but by definition it will be showing you the current thread since you'll
be calling it from Python code. Not helpful if you want to see "from
outside" which thread is active. Generally this doesn't seem to be a
necessary thing however.
> The reason for
> this is I will have threads deadlocked waiting for I/O and I am
> interested to see how often context switching occurs.
You probably mean "blocked waiting for I/O", since "deadlock" generally
implies a bug (maybe involving multiple locks) whereby threads reach a
state where they can never run again (each waiting on a resource held by
the other).
By the way, some of us do a *lot* of thread-work with Python, and don't
seem to have the same concerns as you do... maybe if you just try it
you'll discover some of the things you think you will need aren't really
that important, for whatever reason. (For example, if you can limit
your inter-thread communication to use Queues, you very often won't have
to troubleshoot any thread-related issues like race conditions... they
simply aren't possible in certain configurations.)
-Peter
More information about the Python-list
mailing list