Python extension module with callbacks into Python
Paul Grinberg
gri6507 at gmail.com
Thu Oct 29 14:05:57 EDT 2020
> > Can you please clarify where/when I should call PyEval_InitThreads()? Is this in the main python thread before any pthread callbacks are generated? If so, should this be done only once?
> Do it in your module init. That function is safe to be called multiple time.
>
I decided to do it in the extension module shared library initialization routine. It's guaranteed to be called when the shared library is loaded.
> You could have answered the second part by reading the docs, which is what I did to check what I was telling you.
>
My apologies. I realized that I should have read the manual first, but only after the impulse reaction to send the response.
> Personally I do not code against the C api I use PyCXX to ease a lot of the
> hardship of using the C api. See http://cxx.sourceforge.net/PyCXX-Python3.html
> Disclaimer I am the PyCXX maintainer.
>
> I have c++ classes to handle the Gil release and acquire that I use in pysvn
> that you might find useful.
>
> See http://cxx.sourceforge.net/PyCXX-Python3.html and the
> PythonAllowThreads PythonDisallowThreads classes that to the hard workin a type safe way.
>
Thank you for that reference. I do not write a lot of python extension modules. However, when I do it again, I will seriously consider this as an option.
More information about the Python-list
mailing list