Sujet : Re: PyGILState_Ensure() deadlocks, why?
De : barry (at) *nospam* barrys-emacs.org (Barry Scott)
Groupes : comp.lang.pythonDate : 08. Jul 2024, 10:33:39
Autres entêtes
Message-ID : <mailman.21.1720428030.2981.python-list@python.org>
References : 1 2 3
User-Agent : Apple Mail (2.3774.600.62)
On 7 Jul 2024, at 23:21, Barry via Python-list <python-list@python.org> wrote:
On 7 Jul 2024, at 22:09, Tomas Ukkonen via Python-list <python-list@python.org> wrote:
Py_Initialize();
You also need to tell python to init threading.
I'm in front of my dev machine now and checking up on threading.
There is no longer any extra init for threads required.
I think you are missing more python setup code before you can use threads.
Also i think you need to tell python that your thread wants to call into python.
But I an not near my dev system to research this for you.
You are right to use PyGILState_Ensure()
But as MRAB says the main thread is holding the GIL.
I have code to use python from C++ in my pysvn project.
See the code starting a line 354 in https://sourceforge.net/p/pysvn/code/HEAD/tree/trunk/pysvn/Extension/Source/pysvn.cpp
That saves the thread state and restores it.
You still might find the classes I wrong to manage GIL acquire and release interesting.
I have the C++ type system enforcing the rules of acquire and release.
As well as RAII ensuring never to leave a block with the GIL in the wrong state.
Barry