From 8d8e10347835d4153949c8b144d64b530f309a37 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 30 Oct 2016 22:43:38 +0530 Subject: [PATCH] Bind the event loop to the thread --- kitty/boss.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index b1220ff1f..e3854f2d7 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -32,7 +32,7 @@ class Boss(Thread): Thread.__init__(self, name='ChildMonitor') self.profile = args.profile self.child_fd = create_pty()[0] - self.loop = asyncio.get_event_loop() + self.loop = asyncio.new_event_loop() self.loop.add_signal_handler(signal.SIGINT, lambda: self.loop.call_soon_threadsafe(self.shutdown)) self.loop.add_signal_handler(signal.SIGTERM, lambda: self.loop.call_soon_threadsafe(self.shutdown)) self.loop.add_reader(self.child_fd, self.read_ready) @@ -117,6 +117,7 @@ class Boss(Thread): import pstats pr = cProfile.Profile() pr.enable() + asyncio.set_event_loop(self.loop) self.loop.run_forever() if self.profile: pr.disable() @@ -129,7 +130,7 @@ class Boss(Thread): self.queue_action(self.shutdown) def destroy(self): - # Must be called in the main thread + # Must be called in the main thread as it has signal handlers self.loop.close() del self.loop