Hi again,

I am trying to do something really sillya nd it isn't working:(
I have a main where I want to start two threads using the same handle function, but the second thread generates the following error:

Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:

It's like the first thread is blocking something that the second one needs, but even if the function is executed (meaning the thread exits from what I've been reading ) for the first one before the second one begins, it still gives this error.

What am I to do, what am I to do?

After careful reading of the doc on Python for the thread package :

# When the main thread exits, it is system defined whether the other threads survive. On SGI IRIX using the native thread implementation, they survive. On most other systems, they are killed without executing try ... finally clauses or executing object destructors.

# When the main thread exits, it does not do any of its usual cleanup (except that try ... finally clauses are honored), and the standard I/O files are not flushed.

I figured that main exits before its threads do so that's why everything goes south.

Decision for solution: I put a global flag turned to True at the end of the handler functions for my threads and in the main I put a while not Flag: pass loop which allows the main to wait for the end of the threads... If i never need any more complicated things, this'll keep working like a charm...

what do you think ?

If you want to wait for a thread, the best way is to use the method Thread.join , so you do this

my_thread = Thread(target=...)
my_thread.start()
do_some_stuff()
my_thread.join()

There are times when pyprocessing is a better choice. Using the queue and jointhread may be another solution, but the specifics are only known by yourself.
http://pyprocessing.berlios.de/

Thanks guys, i'll try that :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.