[C++-sig] binding a userspace thread library
Mathieu Lacage
Mathieu.Lacage at sophia.inria.fr
Wed Jan 4 17:03:29 CET 2006
On Wed, 2006-01-04 at 09:06 -0500, Stefan Seefeld wrote:
> Mathieu Lacage wrote:
> > On Wed, 2006-01-04 at 09:34 +0100, Mathieu Lacage wrote:
> >
> >>class MyThread(yans.Thread):
> >> def run(self):
> >> print "before sleep";
> >> sleep_s (1.0);
> >> print "after sleep";
> >>MyThread ("test");
> >>simulator.run ()
> >>simulator.destroy ();
>
> [ no need for all those ';' here, by the way ]
Yes, I am quite new to python so it is hard to resist the perl/sh
compulsion to add ; everywhere.
[snip]
> You didn't actually print the error message you get in the original
> (i.e. non-pdb) session, only the stack trace.
Yes. There is no error message printed at all: it seems the error is
printed by the interpreter's outer loop and the c++ runtime aborted
before giving the interpreter a chance to run.
[snip]
> 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 ? 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 don't know. I guess I will have to see whether or not I can try
to forward exceptions from one thread to another. Or maybe try to deal
with the c++ exception by generating the correct python error myself...
thanks for your suggestions,
Mathieu
--
More information about the Cplusplus-sig
mailing list