Thread: [pygccxml-development] gil_guard_t example ?
Brought to you by:
mbaas,
roman_yakovenko
From: Damien F. <dam...@mo...> - 2008-08-19 11:04:20
|
Hi , some of the member function that we bind can potentially take some time , and we are looking to a way to release the GIL during there execution . looking on the web I see that py++ as some things in place for that : gil_guard_t and I found couple of project using that , but I am still a little confuse on how to use it . is there an example somewhere on how to best use it ? Thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-08-19 12:43:58
|
On Tue, Aug 19, 2008 at 2:04 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > some of the member function that we bind can potentially take some time > , and we are looking to a way to > release the GIL during there execution . > > looking on the web I see that py++ as some things in place for that : > gil_guard_t > and I found couple of project using that , but I am still a little > confuse on how to use it . gil_guard_t is used for completely other purposes. If you have algorithm, written in C++, which invokes code written in Python, than you have to lock GIL. This is exactly what gil_guard_t does. Not the opposite. > is there an example somewhere on how to best use it ? No -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-08-19 13:19:08
|
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);' ) ..... so could I use the transformer to write a little wrapper that would do what I need ? 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 ); } or some things like that ? Thanks Damien > On Tue, Aug 19, 2008 at 2:04 PM, Damien Fagnou > <dam...@mo...> wrote: > >> Hi , >> >> some of the member function that we bind can potentially take some time >> , and we are looking to a way to >> release the GIL during there execution . >> >> looking on the web I see that py++ as some things in place for that : >> gil_guard_t >> and I found couple of project using that , but I am still a little >> confuse on how to use it . >> > > gil_guard_t is used for completely other purposes. > > If you have algorithm, written in C++, which invokes code written in > Python, than you have to lock GIL. This is exactly what gil_guard_t > does. > > Not the opposite. > > >> is there an example somewhere on how to best use it ? >> > > No > > |
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/ |