[C++-sig] Re: serializing threaded access to Boost.Python-wrapped class

Vladimir Prus ghost at cs.msu.su
Thu Apr 14 11:32:26 CEST 2005


Eric wrote:

> I have a C++ class, accessed from python via Boost.Python, that I am
> trying to prevent from being reentered in the context of a multithreaded
> program. I can do this relatively easily with the RLock class in the
> threading module. However this requires me to track down every caller of
> this class and wrap all calls in an acquire()/release() pair. I'm worried
> that it would be pretty easy to miss one of these and then cause
> hard-to-find bugs.
> 
> Is there any way to do this automatically with Boost.Python?

There's a Python-only solution -- after importing a class, you can walk over
all its methods, and "decorate" them, adding any pre/post processing you
like. The attached example does this with the 'hello' class from
'example/getting_started2' example.

This is much easier that tracking down every caller -- this only requires to
to call a function for each imported *class*.

- Volodya


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pre_post.py
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050414/7fb0cb8f/attachment.txt>


More information about the Cplusplus-sig mailing list