c bindings with non-python thread callback while python exits

2021-01-26 Thread Paul Grinberg
I have a C++ library (luckily with source code, so I know what's going on) to which I wrote c bindings. The library internally starts an event pthread which generates callbacks back into python. The c binding for processing these callbacks look like this (simplified for convenience): PyGILState

Python extension module with callbacks into Python

2020-10-27 Thread Paul Grinberg
As full disclosure, I posted this question on StackOverflow as well, but it looks like questions with [Python] [Extension-Module] tags are not frequently answered. The link to my question there is https://stackoverflow.com/questions/64559322/python-extension-module-with-callbacks-into-python I

Re: Python extension module with callbacks into Python

2020-10-28 Thread Paul Grinberg
> > I am running into unpredictable behavior with my Python extension module > > that wraps around a C++ library that starts a new pthread and, after doing > > some work, generates callbacks back into the caller. I've greatly > > simplified this to a simplistic example which still demonstrates t

Re: Python extension module with callbacks into Python

2020-10-28 Thread Paul Grinberg
> 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? -- https://mail.python.

Re: Python extension module with callbacks into Python

2020-10-29 Thread Paul Grinberg
> > 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