Calling into Python from a C thread
Philip Semanchuk
philip at semanchuk.com
Tue Feb 10 10:29:15 EST 2009
On Feb 9, 2009, at 3:59 PM, Christian Heimes wrote:
> Philip Semanchuk wrote:
>> Yes, that's accurate except for the word "forgot". To forget
>> something
>> one must first know it. =) I found the threading API documentation
>> difficult to follow, but I suppose that what I'm doing is a little
>> unusual so if it is not well-documented territory, that's what I
>> get for
>> wandering off the map.
>
> I see. Apparently the threading and embedding docs don't cover your
> case. The docs at
> http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock
> and http://docs.python.org/extending/embedding.html should explain how
> and when to initialize Python threads. Please report a documentation
> bug at
> http://bugs.python.org/.
I read that several times and eventually got my code working. I
wouldn't say that the documentation didn't cover my case (implementing
a callback). I'd say that it doesn't cover *any* cases in particular.
It's more like a list of tools for manipulating the GIL and thread
state and an explanation of the need for them rather than a tutorial
on how to use them. The latter is what I needed, but as I said, what
I'm doing is atypical and I think it is reasonable to expect thin
documentation on atypical situations.
> PS: I know a great way to learn more about Python's internal threading
> CAPI: fix your code, test it and attach a doc patch to your bug
> report.
> *hint* :)
I will file a bug on a least one specific point which is that
PyGILState_Ensure() acquires the GIL and PyGILState_Release() appears
to release it; the latter point is undocumented.
Cheers
Philip
More information about the Python-list
mailing list