checking a thread has started

Deepak Sarda deepak.sarda at gmail.com
Sat Nov 6 13:29:12 EST 2004


On Sat, 06 Nov 2004 09:30:59 -0800, Josiah Carlson <jcarlson at uci.edu> wrote:
> > I believe this bottleneck is due to Apache server - it just can't
> > spawn so many threads so quickly. It just spawns seven threads and
> > that's it.
> 
> Is it also possible that your threads are finishing before you get done
> spawning them?

I don't think so. As I said earlier, the run() method isn't even
called for some threads.

> 
> 
> > My question is: how do I check whether a call to the start() method
> > was successful? If there is a mechanism by which I can get this
> > information - I can try restarting/recreating the thread.
> 
> lst = [(func, args, kwargs), ...]
> i = 0
> while i < len(lst):
>     count = len(threading.enumerate())
>     threading.Thread(target=lst[i][0],
>                      args=lst[i][1],
>                      kwargs=lst[i][2]).start()
>     if len(threading.enumerate()) > count:
>         i += 1
>     else:
>         #You really don't want this to loop as fast as it can.
>         #1/100 of a second timeout will keep this from being a
>         #processor hog...at least during thread startup.
>         time.sleep(.01)
> 

This seems like a way to workaround the problem. I'll try it on Monday
and get back if it works. But this does bring up the point that
threading.Thread() should provide some mechanism by which a thread's
inability to start should be known. a return value or something. (I am
a newbie to threads - python is the first language I am trying threads
in so please educate me if I have wrong notions! :-)

> As an aside, are you sure you need 15 threads?  Seems a little over the
> top to me.

I do. This program sits on top of a cluster and ferries jobs to the
compute nodes - an embarrassingly parallel problem with fifteen
subtasks.

Thanks for the reply.

Deepak



More information about the Python-list mailing list