Re: [pygccxml-development] Help needed with embedding
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-08-04 10:02:07
|
On Tue, Aug 4, 2009 at 12:27 PM, Berserker<ber...@ho...> wrote: > Thanks for the quick reply Roman > >> This is a quick solution. By the way Py++ defines gil_guard_t class( >> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/gil_guard.py?revision=1428&view=markup >> ) > > Thanks for the link but gil_guard_t acquires and releases the GIL allowing > to operate on the CPython API, instead we need to release the lock > (PyEval_SaveThread) before the c++ function invocation and to acquire it > again (PyEval_RestoreThread) after allowing multiple interpreters to run > concurrently during the c++ code execution where no CPython API will be > touched Sorry for misunderstanding. >> I guess it is possible to create custom call policy, so the code will look >> like: > >> boost::python::class_< Foo >("Foo") >> .def("test_method_1", &Foo::test_method_1, >> pythread_safe<return_value_policy< ... > >() ); > > I have tried this solution with a custom policy that calls PyEval_SaveThread > in the "precall" function and PyEval_RestoreThread in the "postcall" > function (according to > http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/default_call_policies.html > ) but unfortunately after the precall's policy boost::python works on the > CPython API before of the handler invocation (converting arguments for > example), instead with a custom visitor (like that in libtorrent) we can > surround the c++ code invocation with PyEval_SaveThread/PyEval_RestoreThread > exactly before/after its execution where, as I said before, no CPython API > will be touched for sure. > I still think that something like: > >> boost::python::class_< Foo >("Foo") >> .def("test_method_1", allow_threads(&Foo::test_method_1))>; > > is the best solution, any hope to support this? Did you implement "allow_threads"? If yes, can you publish it and some usage example? If not, I guess you thought about it, right ? Do you mind to share your thoughts? This is an interesting question, and may be you should take it to Boost.Python mailing list. Whatever solution the list will come with, it will be possible to integrate it with Py++. >> tm.add_override_precall_code( ... ) >> tm.add_default_precall_code( ... ) > > add_override_precall_code is exactly what we need but "strangely" no code is > added when the allow_threading_transformer_t is added to the function (we > still need the transformer as I mentioned above until the "visitor" patch), > my code: > >> tm.add_transformation(allow_threading_transformer_creator()) >> tm.add_override_precall_code(gil_guard_code) > > If I comment the "add_transformation" line, the override_precall_code is > correctly added to the wrapper. Any advice? Yes: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/function_transformers/templates.py?revision=1467&view=markup The short version: if you applied a transformation, than everything should be done in it. The long version: you can modify the templates so it will release the GIL. You can do it without changing Py++ code. >> Is this an open source project? > > It will be :) > Here it is the link http://osiris.kodeware.net/ if you are interested :) :-). Very cool project. > Thanks again for your help You are welcome. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |