Search code examples
pythoncmultithreadingpython-c-api

How do I get the current PyInterpreterState?


I'd like to create a PyThreadState since there doesn't appear to be one for the current thread.

How do I get the current PyInterpreterState to pass to PyThreadState_New(...), or is that something that I should only do if I'm embedding an interpreter (and thus have created it), rather than calling into a library from python?


Solution

  • It turns out that not having a PyThreadState in the main thread is a fatal error. It was caused for me by two different python versions both being linked at the same time, so this question is somewhat moot.