3 from __future__
import absolute_import
10 from gi
.repository
import GLib
12 from .helper
import capture_exceptions
15 class TestMainLoop(unittest
.TestCase
):
17 @unittest.skipUnless(hasattr(os
, "fork"), "no os.fork available")
18 def test_exception_handling(self
):
19 pipe_r
, pipe_w
= os
.pipe()
24 select
.select([pipe_r
], [], [])
28 def child_died(pid
, status
, loop
):
30 raise Exception("deadbabe")
32 loop
= GLib
.MainLoop()
33 GLib
.child_watch_add(GLib
.PRIORITY_DEFAULT
, pid
, child_died
, loop
)
36 os
.write(pipe_w
, b
"Y")
39 with
capture_exceptions() as exc
:
43 assert exc
[0].type is Exception
44 assert exc
[0].value
.args
[0] == "deadbabe"
46 @unittest.skipUnless(hasattr(os
, "fork"), "no os.fork available")
47 @unittest.skipIf(os
.environ
.get("PYGI_TEST_GDB"), "SIGINT stops gdb")
48 def test_sigint(self
):
52 # wait for the parent process loop to start
56 os
.kill(os
.getppid(), signal
.SIGINT
)
60 # tell the child that it can kill the parent
64 GLib
.idle_add(notify_child
)
65 loop
= GLib
.MainLoop()
68 self
.fail('expected KeyboardInterrupt exception')
69 except KeyboardInterrupt:
71 self
.assertFalse(loop
.is_running())