[C++-sig] binding a userspace thread library

Stefan Seefeld seefeld at sympatico.ca
Wed Jan 4 17:20:18 CET 2006


Mathieu Lacage wrote:

>>So: if you prepare your thread's private 'run' method to catch
>>errors (by terminating the thread properly, probably), you will
>>get much nicer error messages.
> 
> 
> I see. I now terminate the c++ thread properly (that is, I catch and
> ignore the exception) and I now get this:
> 
> [mlacage at chronos yans-current]$ ./bin/python/test-thread.py
> before sleep
> Exception exceptions.NameError: "global name 'time_s' is not defined" in 'garbage collection' ignored
> Fatal Python error: unexpected exception during garbage collection
> Aborted
> [mlacage at chronos yans-current]$
> 
> This error message does not look quite right: it looks like a collision
> of two error messages. Am I wrong ?

To me it looks plausible: The worker thread writes 'before sleep' and
then stops. The error you are seeing then seems to be coming from
the cleanup at the end of your script, i.e. it appears to be an entirely
different issue.


> I suspect this might be related to
> the fact that I am not forwarding properly the c++ exception from my
> thread to the interpreter's thread. I tried calling a python method with
> the same problem from a c++ function called from the c++ interpreter and
> I got the following message instead:
> 
> Traceback (most recent call last):
>   File "./bin/python/test-simulator.py", line 34, in ?
>     simulator.run ()
>   File "./bin/python/test-simulator.py", line 7, in notify
>     print "my event class now=%f" % now_s ();
> NameError: global name 'now_s' is not defined
> 
> I suspect that the c++ exception I ignore is interpreted correctly by
> the boost bindings which re-generate the correct python error. Or maybe
> not.

I'm not sure. Are you saying that the 'now_s()' call should actually succeed ?
May be you are right, and you need to clear the error flag first before
terminating the worker thread. Try calling 'PyErr_Clear()' in your exception
handler in the worker thread. (see http://docs.python.org/api/exceptions.html)

Regards,
		Stefan



More information about the Cplusplus-sig mailing list