aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtCore/bug_PYSIDE-164.py
diff options
context:
space:
mode:
authorPankaj Pandey <pankaj86@gmail.com>2014-05-01 19:58:03 +0530
committerJohn Ehresman <jpe@wingware.com>2014-07-08 02:01:05 +0200
commit0c64d1b2c6e5e0951675ad9b22294db4a10741c7 (patch)
tree40a7680fd968bfb6c27f777b90d3a6aadd058db9 /tests/QtCore/bug_PYSIDE-164.py
parent8dfeddb3a679d2f6fdb1ae01f8eee77c9bec7edd (diff)
PYSIDE-164: Fix possible deadlock on signal connect/emitps-4.8-head
Signal connect/emit acquire a lock on the QObject, and can happen from python code (which has acquired the GIL) or internal QtCode (without acquiring the GIL). So we always need to release the GIL to prevent out-of-order acquisition of the locks causing deadlock. Change-Id: I1cf47a73c2b60627e322d8ef3fa4c3efdebd4c02 Reviewed-by: John Ehresman <jpe@wingware.com>
Diffstat (limited to 'tests/QtCore/bug_PYSIDE-164.py')
-rw-r--r--tests/QtCore/bug_PYSIDE-164.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/QtCore/bug_PYSIDE-164.py b/tests/QtCore/bug_PYSIDE-164.py
new file mode 100644
index 000000000..53a1bd6c2
--- /dev/null
+++ b/tests/QtCore/bug_PYSIDE-164.py
@@ -0,0 +1,39 @@
+from PySide.QtCore import QCoreApplication, QEventLoop, QObject, Qt, QThread, QTimer, SIGNAL
+import unittest
+
+
+class Emitter(QThread):
+ def __init__(self):
+ QThread.__init__(self)
+
+ def run(self):
+ print "Before emit."
+ self.emit(SIGNAL("signal(int)"), 0)
+ print "After emit."
+
+class Receiver(QObject):
+ def __init__(self, eventloop):
+ QObject.__init__(self)
+ self.eventloop = eventloop
+
+ def receive(self, number):
+ print "Received number: %d" % number
+ self.eventloop.exit(0)
+
+
+class TestBugPYSIDE164(unittest.TestCase):
+
+ def testBlockingSignal(self):
+ app = QCoreApplication.instance() or QCoreApplication([])
+ eventloop = QEventLoop()
+ emitter = Emitter()
+ receiver = Receiver(eventloop)
+ emitter.connect(emitter, SIGNAL("signal(int)"),
+ receiver.receive, Qt.BlockingQueuedConnection)
+ emitter.start()
+ retval = eventloop.exec_()
+ emitter.wait()
+ self.assertEqual(retval, 0)
+
+if __name__ == '__main__':
+ unittest.main()