[XML-SIG] Advice on how to deal with locking problems using python-wrapped C libs in MT frameworks like Zope/Twisted?

M.-A. Lemburg mal@lemburg.com
Mon, 31 Mar 2003 11:35:35 +0200


Daniel Veillard wrote:
> On Mon, Mar 31, 2003 at 06:53:54AM +0200, "Martin v. L=F6wis" wrote:
>=20
>>Daniel Veillard schrieb:
>>
>>>>What mechanism in libxslt does make the callback? Is that Python code=
,
>>>>or code implemented in libxslt itself?
>>>
>>>
>>>  In libxslt as I posted but that can be overriden.
>>
>>That probably explains the deadlock: I assume libxslt is holding the GI=
L
>>when that happens?
>=20
>   No idea what the GIL is, I don't take nor release any lock at the C o=
r
> python level.

The GIL is the global Python interpreter lock. A Python extension
can release it whenever long running IO will happen. When using
callbacks you have to watch out though because releasing the GIL
can cause the interpreter to call back into your extension,
so that'll have to be thread safe.

Here's an example of how to release the GIL in C:

	Py_BEGIN_ALLOW_THREADS;
	/* Call into some C lib */
	Py_END_ALLOW_THREADS;


--=20
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Mar 31 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
Python UK 2003, Oxford:                                     one day left
EuroPython 2003, Charleroi, Belgium:                        85 days left