![](https://secure.gravatar.com/avatar/426cd17f6e4e399d6d92f2a3e14cde23.jpg?s=120&d=mm&r=g)
Jan. 9, 2003
4:07 a.m.
[Martin]
Tim Peters <tim.one@comcast.net> writes:
I'd like to intensify the problem, though: you're in a thread and you want to call a Python API function safely. Period.
Are there semantic requirements to the Python API in this context, with respect to the state of global things? E.g. when I run the simple string "import sys;print sys.modules", would I need to get the same output that I get elsewhere? If yes, is it possible to characterize "elsewhere" any better?
Yes, good catch. A PyInterpreterState must be known, and as you stated previously, it is trivial to get one of these and stash it away globally. The PyThreadState is the problem child. Mark.