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

Mathieu Lacage Mathieu.Lacage at sophia.inria.fr
Wed Jan 4 11:30:16 CET 2006


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 ();

[snip]

> Suggestions about a way to debug this ?

After quite a bit of debugging (I learned quite a few things about
Boost.Python and the python c interface), it appears that the error here
is that the python script does not qualify the calls to sleep_s with
self.

That is, the following script works flawlessly:
class MyThread(yans.Thread):
    def run(self):
        print "before sleep";
        self.sleep_s (1.0);
        print "after sleep %f" % self.time_s ();
thread = MyThread ("test");
simulator.run ()
simulator.destroy ();


I have to say that the python interpreter gives a better error message
only when run under the debugger. i.e.:
[mathieu at mathieu yans-current]$ python -m pdb ./bin/python/test-thread.py
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(3)?()
-> import yans;
(Pdb) n
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(4)?()
-> from yans import *;
(Pdb)
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(6)?()
-> class MyThread(yans.Thread):
(Pdb)
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(16)?()
-> thread = MyThread ("test");
(Pdb) b MyThread.run
Breakpoint 1 at /home/mathieu/code/yans-current/bin/python/test-thread.py:8
(Pdb) c
SCHED leave main enter "test" active
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(9)run()
-> print "before sleep";
(Pdb) n
before sleep
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(12)run()
-> print "after sleep %f" % time_s ();
(Pdb)
NameError: "global name 'time_s' is not defined"
 > /home/mathieu/code/yans-current/bin/python/test-thread.py(12)run()
-> print "after sleep %f" % time_s ();
(Pdb)

The lack of a better error message by default for such a mistake is...
annoying... Is there a way to improve this ?

Mathieu
-- 




More information about the Cplusplus-sig mailing list