[PyQt] Exception handling crash
Phil Thompson
phil at riverbankcomputing.com
Fri Jun 13 14:05:05 BST 2008
On Friday 13 June 2008 1:45:09 pm Arve Knudsen wrote:
> On 6/13/08, Phil Thompson <phil at riverbankcomputing.com> wrote:
> > On Friday 13 June 2008 10:54:47 am Arve Knudsen wrote:
> > > Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS in the API:
> > > PyGILState_Ensure/PyGILState_Release. Could SIP make use of these
> > > functions instead?
> >
> > They are not alternatives. One pair frees the GIL for a period, the other
> > acquires the GIL for a period.
>
> In order to free the GIL, you have to acquire it first no? Therefore,
> BEGIN_ALLOW/END_ALLOW, should correspond to GILState_Release of a
> previously Ensure'd GIL state and then a new call to
> PyGILState_Ensure. Besides, the Python docs
> (http://docs.python.org/api/threads.html) present the PyGILState_*
> functions as a simpler alternative to Py_BEGIN_ALLOW_THREADS et al.
The documentation is misleading at best. Both pairs are intended to be used in
the same scope. Ensure/Release make it easier to use across different scopes
and to use Release then Ensure if you want to - but you then have to maintain
a separate stack of the GIL states.
If you use them the way they are supposed to be used then you use the C
stack - see the definition of SIP_BLOCK_THREADS and SIP_UNBLOCK_THREADS.
Phil
More information about the PyQt
mailing list