Browse Source

Handle exiting more gracefully

Set all threads to daemon mode and close
the write end of the pipe when exiting to
ensure we cleanup in a friendly manner.

Change-Id: I4cf64fa39e820c95d11943b848db87e5db15212e
changes/91/391991/1
Joshua Harlow 8 years ago
parent
commit
5500eca644
  1. 15
      gertty/gertty.py
  2. 1
      gertty/sync.py

15
gertty/gertty.py

@ -13,6 +13,7 @@
# under the License.
import argparse
import contextlib
import logging
import os
import sys
@ -121,15 +122,21 @@ class App(object):
self.status.update(title=screen.title)
self.loop = urwid.MainLoop(screen, palette=palette,
unhandled_input=self.unhandledInput)
sync_pipe = self.loop.watch_pipe(self.refresh)
self.sync_pipe = self.loop.watch_pipe(self.refresh)
#self.loop.screen.set_terminal_properties(colors=88)
if not disable_sync:
self.sync_thread = threading.Thread(target=self.sync.run, args=(sync_pipe,))
self.sync_thread = threading.Thread(target=self.sync.run, args=(self.sync_pipe,))
self.sync_thread.daemon = True
self.sync_thread.start()
else:
self.sync_thread = None
def run(self):
self.loop.run()
def close(self):
os.close(self.sync_pipe)
def changeScreen(self, widget):
self.status.update(title=widget.title)
self.screens.append(self.loop.widget)
@ -173,6 +180,8 @@ class App(object):
self.backScreen()
elif key == 'f1':
self.help()
elif key in ('q', 'Q'):
raise urwid.ExitMainLoop()
def getRepo(self, project_name):
local_path = os.path.join(self.config.git_root, project_name)
@ -192,3 +201,5 @@ if __name__ == '__main__':
help='the server to use (as specified in config file)')
args = parser.parse_args()
g = App(args.server, args.debug, args.no_sync)
with contextlib.closing(g):
g.run()

1
gertty/sync.py

@ -377,6 +377,7 @@ class Sync(object):
self.submitTask(SyncSubscribedProjectsTask(HIGH_PRIORITY))
self.submitTask(UploadReviewsTask(HIGH_PRIORITY))
self.periodic_thread = threading.Thread(target=self.periodicSync)
self.periodic_thread.daemon = True
self.periodic_thread.start()
def periodicSync(self):

Loading…
Cancel
Save