Re: [pygccxml-development] gil_guard_t example ?
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2008-08-19 20:11:52
|
On Tue, Aug 19, 2008 at 4:19 PM, Damien Fagnou <dam...@mo...> wrote: > Looking at the result that was what it looked it does > but in one use of it in pyopensg there is those comments that miss lead me > ... > > def unlocked_native(): > ''' > Returns a function transform creator for native functions and methods that > do not hold the GIL while they execute. > ''' > > this use a derived class from FT.transformer_t > with : > def required_headers(self): > return [ pyplusplus.code_repository.gil_guard.file_name ] > > def __configureSealed(self, controller): > # Create a guard for the GIL before the actual fucntion call is made. > # This is an exception-safe approach to managing the GIL. > controller.add_pre_call_code( > 'pyplusplus::threading::gil_guard_t guard(true);' > ) > ..... https://realityforge.vrsource.org/trac/pyopensg/changeset/505 I took a look on the code. May be I am missing something, but the effect achieved is the opposite one. Here is a link to Python documentation: http://docs.python.org/api/threads.html > so could I use the transformer to write a little wrapper that would do what > I need ? May be you not. RAII ( http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization ) is a popular design pattern, so Py++ makes developers life easier. Take a look on http://www.language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.calldef_wrapper.member_function_t-class.html add_override_precall_code add_default_precall_code methods. > static boost::python::object applyTo_0fec81cf95d5ecaac2dd1187f0efac01( ... > .... ) > { > ::Muggins::MugginPtr result; > { > /// a object that wrapper the GIL unlocking > scoped_releaseGIL(); > /// my functiontion call > result = inst.applyTo(target); > } > return bp::object( result ); > } The last statement invokes Python, so it has to lock GIL. You can use gil_guard_t and its "ensure" and "release" functions. > or some things like that ? More or less. I don't have a clear example, so cant give you good advice. May be, after all you will have to create custom transformation - in this case, don't forget to contribute it :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |