Python extension module with callbacks into Python

Barry barry at barrys-emacs.org
Wed Oct 28 17:50:33 EDT 2020



> On 28 Oct 2020, at 15:22, Paul Grinberg <gri6507 at gmail.com> wrote:
> 
> 
>> 
>> Try calling PyEval_InitThreads() to force the python threading to be all setup. 
> 
> 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.

You could have answered the second part by reading the docs, which is what I did to check what I was telling you.

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.

Barry

> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 


More information about the Python-list mailing list