[PyQt] Regrettable behaviour of threading.local in QThread

Andrew Suffield asuffield at suffields.me.uk
Sat Apr 7 06:42:27 BST 2012

The attached script creates a threading.local within a QThread, and
stores a value in it. It then reads this value back immediately, and
later from an event handler.

Unexpectedly, by the time we get to the event handler, the contents of
the threading.local has been destroyed.

I suspect there are infelicitious interactions between QThread,
thread._local, and the garbage collector. I haven't looked closely;
it's easier to work around the problem. It's possible this is a python
bug in the handling of alien threads.

Tripped over this one because it breaks sqlalchemy's scoped_session
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-thread-local-test.py
Type: text/x-python
Size: 848 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120407/d644e7f6/attachment.py>

More information about the PyQt mailing list