[PyQt] Any way to run code before each QThread?
John Ehresman
jpe at wingware.com
Mon Jul 16 16:03:51 BST 2018
On 7/15/18 8:19 PM, Ned Batchelder wrote:
> How does Wing wrap the run method? How does it get a chance to do that?
Wing monkeypatches QThread to replace QThread.__init__ with it's own
callable after the QtCore module is loaded. Within the __init__
replacement, the .run method on the new instance is replaced by a
replacement run callable that calls settrace before calling the saved
run method. This is done because user code does override the run method
in subclasses of QThread and monkeypatching in __init__ captures the
overridden run method in most cases. I've attached a snippet of Wing's
code; it's an extract and won't run as is but hopefully it's helpful.
This is an ugly hack and there is code that it won't work for, but it
should work most of the time.
Cheers,
John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qthreadhack.py
Type: text/x-python-script
Size: 2015 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180716/92176e99/attachment.bin>
More information about the PyQt
mailing list