[PyKDE] QMutexLocker doesn't unlock the mutex if an exception
israised
Giovanni Bajo
rasky at develer.com
Sat Sep 16 20:03:00 BST 2006
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
>> the Qt4/PyQt4 manuals specifically talk about using QMutexLocker to
>> simplify exception handling in functions. However, in PyQt the mutex
>> doesn't get unlocked if an exception is raised in the function code.
>> I was wondering whether this is a bug or a technical limitation? If
>> the latter, then perhaps it could be mentioned in the PyQt manual?
>
> It's a feature of the way Python exceptions work. The locals aren't
> garbage collected (and so the mutex isn't unlocked) while the
> exception is being handled. Doing something like...
>
> try:
> raise Exception
> finally:
> del locker
>
> ...fixes it, but I agree that that rather misses the point of
> QMutexLocker in the first place.
I guess it would be a better compromise if QMutexLocker supported the new with
statement in Python 2.5:
with locker:
# code
and the fact was then mentioned in the documentation of PyQt.
Giovanni Bajo
More information about the PyQt
mailing list