checking a thread has started

Deepak Sarda deepak.sarda at gmail.com
Sat Nov 6 21:34:40 EST 2004


On Sat, 06 Nov 2004 15:18:59 -0800, Josiah Carlson <jcarlson at uci.edu> wrote:
> 
> 
> 
> Deepak Sarda <deepak.sarda at gmail.com> wrote:
> >
> > On Sat, 06 Nov 2004 09:30:59 -0800, Josiah Carlson <jcarlson at uci.edu> wrote:
> > 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! :-)
> 
> If a thread doesn't start due to lack of resources, I think it should be
> raising an exception.
> 

I would think so too. But it isn't. If you look at the code in
threading.py - there' s this line:

def start(self):
     [snip]
     _sleep(0.000001)    # 1 usec, to let the thread run (Solaris hack)

Does apache need a similar hack?


> As an aside, I wrote a little script that creates 1000 threads, does a
> busy loop for a short time, then exits; it had no problems with a few
> hundred threads at a time (though it was a bit slow), and I didn't see
> any exceptions.  Perhaps I should have been incrementing a counter when
> it started and finished.
> 
> 

But did you run it through apache? For me, the script runs fine
locally - it's only when run through apache that I get this problem.

> > > 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.
> 
> Sounds like a job for asyncore (if you can handle asynchronous
> servers/clients).

I've never user asyncore before. I just read it's documentation and it
seems to be organized around sockets. I don't think I want this I am
not directly communicating with remote nodes.  The actual movement of
jobs to the nodes is done by the Sun Grid Engine software sitting on
the head node. I just create jobs and submit it to the local engine
through a os.spawnl() call in each thread. The engine then decides
which node is free and sends the job(s) there.

-- 

Online: http://www.antrix.net/journal/



More information about the Python-list mailing list