-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use it with multithreading? #263
Comments
Have you tried |
From what I gathered the problem comes from not checking that the call into python proc `=destroy`*(p: var PyObject) =
if not p.rawPyObj.isNil:
let ts = PyThreadState_Swap(pyMainThread)
decRef p.rawPyObj
discard PyThreadState_Swap(ts)
p.rawPyObj = nil I initialize |
Is there a solution to this that can be achieved without modifying the source? |
|
I am using nimpy to call into python across multiple threads.
I hold a lock whenever I use python functions, such that only one thread at a time calls into python.
But this doesn't seem to be enough.
I get segfaults with a traceback pointing to the pyobject destructor.
So I assume that holding a lock is not enough to be GIL safe, because the destructor implemented in nimpy is not GIL safe.
I tried to hold the lock myself with this, but in my code I got stalls, maybe because the
PyGILState_Ensure
call stops the nim threading runtime I don't know:In my case I ended up using threadvars, but I don't know why it works, even if the vars are globals, shouldn't a new assignment trigger a destructor on the previous object?
The text was updated successfully, but these errors were encountered: