Re: [pygccxml-development] Help needed with embedding
Brought to you by:
mbaas,
roman_yakovenko
From: Berserker <ber...@ho...> - 2009-08-04 09:28:13
|
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 > 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? > 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? > Is this an open source project? It will be :) Here it is the link http://osiris.kodeware.net/ if you are interested :) Thanks again for your help _________________________________________________________________ Scarica i nuovi gadget per personalizzare Messenger! http://www.messenger.it/home_gadget.aspx |