help with threads

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Aug 7 04:47:55 EDT 2009


Michael Mossey wrote:
> Hello,
>
> I have a simple application that needs one thread to manage networking
> in addition to the main "thread" that does the main job. It's not
> working right. I know hardly anything about threads, so I was hoping
> someone could point me in the right direction to research this.
>
> Basically, I have a program that does some computational work, and
> also conveys its status to a monitor program elsewhere on the network
> via sockets. I wanted to use a thread to manage the networking so that
> the main program can run without regard to networking (i.e. they would
> be asynchronous). So the network thread loops and calls select.
>
> My problem is that in some cases, the network thread appears to stop,
> while the main thread is doing a long computation.
>
> I'm hoping someone can give me a general idea what to read about. For
> example, under what conditions does a thread stop running? Can other
> threads "take priority"? Are there certain operations that block other
> threads (such as disk access)?
>
> Thanks,
> Mike
>   
I may be a little out of subject, anyway *if* you are writing also the 
server side program, you should really take a look at
http://docs.python.org/library/xmlrpclib.html
or
http://pyro.sourceforge.net/

... and forget about network coding :o)

To help you for your initial question, exceptions in thread are not 
propagated to the main thread, so when an unhanded exception occurs in 
your thread, it will just stop. Maybe this is what is happening.

A quick workaround is to embed all you threaded code in a try except 
clause and log the exception before re-raising it. You should only do 
that for debugging purpose.

JM



More information about the Python-list mailing list