summaryrefslogtreecommitdiff
path: root/tests/test_mainloop.py
diff options
context:
space:
mode:
authorMartin Pitt <martinpitt@gnome.org>2012-04-03 22:26:34 +0200
committerMartin Pitt <martinpitt@gnome.org>2012-04-03 22:26:34 +0200
commit2a5a33a9c9c170830c98c2e32fa8dcea3c35f2e6 (patch)
treeac6a97ca43af0fac59e0366c9c9b60683ff4e353 /tests/test_mainloop.py
parentd03696c1aaa7e66f8f16554cf4a4b97addb5aea1 (diff)
downloadpygobject-2a5a33a9c9c170830c98c2e32fa8dcea3c35f2e6.tar.gz
Add test case for multiple GLib.MainLoop instances
Commit 832f16f9 fixed a lockup with multiple GLib.MainLoops. Add corresponding test case. https://bugzilla.gnome.org/show_bug.cgi?id=663068
Diffstat (limited to 'tests/test_mainloop.py')
-rw-r--r--tests/test_mainloop.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index fa6192ed..934b23b8 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -3,6 +3,9 @@
import os
import sys
import select
+import signal
+import thread
+import time
import unittest
from gi.repository import GLib
@@ -11,7 +14,7 @@ from compathelper import _bytes
class TestMainLoop(unittest.TestCase):
- def testExceptionHandling(self):
+ def test_exception_handling(self):
pipe_r, pipe_w = os.pipe()
pid = os.fork()
@@ -50,3 +53,23 @@ class TestMainLoop(unittest.TestCase):
#
sys.excepthook = sys.__excepthook__
assert not got_exception
+
+ def test_concurrency(self):
+ def on_usr1(signum, frame):
+ pass
+
+ try:
+ # create a thread which will terminate upon SIGUSR1 by way of
+ # interrupting sleep()
+ orig_handler = signal.signal(signal.SIGUSR1, on_usr1)
+ thread.start_new_thread(time.sleep, (10,))
+
+ # now create two main loops
+ loop1 = GLib.MainLoop()
+ loop2 = GLib.MainLoop()
+ GLib.timeout_add(100, lambda: os.kill(os.getpid(), signal.SIGUSR1))
+ GLib.timeout_add(500, loop1.quit)
+ loop1.run()
+ loop2.quit()
+ finally:
+ signal.signal(signal.SIGUSR1, orig_handler)