Skip to content

Instantly share code, notes, and snippets.

@gdementen
Last active December 17, 2015 15:59
Show Gist options
  • Save gdementen/5635128 to your computer and use it in GitHub Desktop.
Save gdementen/5635128 to your computer and use it in GitHub Desktop.
How to release the GIL inside a numba function through ctypes
from ctypes import pythonapi, c_void_p
from numba import autojit
savethread = pythonapi.PyEval_SaveThread
savethread.argtypes = []
savethread.restype = c_void_p
restorethread = pythonapi.PyEval_RestoreThread
restorethread.argtypes = [c_void_p]
restorethread.restype = None
@autojit
def test_gil():
threadstate = savethread()
restorethread(threadstate)
test_gil()
@gdementen
Copy link
Author

adding proper arg/res types fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment