Use of Py_BEGIN_ALLOW_THREADS?
Aahz Maruch
aahz at panix.com
Thu Apr 19 15:59:14 EDT 2001
In article <3AD42A5F.73AE10EC at rfa.org>, Bill Eldridge <bill at rfa.org> wrote:
>
>I'm calling a C function from Python, and that C function in turn calls
>another C function #2 with a C callback function.
>
>Somewhere it seems like with threads it disappears - all of the debug
>messages in function #2 come out, but the C callback never gets called.
So you're saying that this works correctly if you don't use threads?
What happens if you have multiple threads, but only one thread calls the
original C function? My suspicion is that you're getting cross-thread
contamination in your C code because it isn't thread-safe.
Note that you should *ONLY* use Py_BEGIN_ALLOW_THREADS if your code is
"thread hot"; that is, not just thread-safe, but designed to allow
multiple threads into the same code at the same time. In the absence of
Py_BEGIN_ALLOW_THREADS, your C code is considered to be one Python
bytecode and executes as a single unit.
--
--- Aahz <*> (Copyright 2001 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het Pythonista http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"Beware of companies that claim to be like a family. They might not be
lying." --Jill Lundquist
More information about the Python-list
mailing list