monkeyBox
August 25th, 2010, 07:21 PM
I'm writing a python daemon and I'd like for it to show an indicator icon when it's running (in the future I'll likely add a menu to the icon for misc. options).
My daemon has a basic "while: True" main loop. So, I can't put gtk.run() in my main thread. My solution was to put the indicator code, along with gtk.run() in a separate thread, as such:
gtk.gdk.threads_init()
class IndicatorThread(Thread):
"Separate thread for gnome indicator icon"
def run(self):
self.ind = appindicator.Indicator("tracker-daemon", "gtg-panel",
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
menu = gtk.Menu()
self.ind.set_menu(menu)
self.running = True
gtk.main()
def stop(self):
if getattr(self, 'running', False):
gtk.main_quit()
This works for the most part, but my daemon hangs when I kill it or when I do a debug breakpoint using ipdb.set_trace().
Am I going about this all wrong? Is there no clean way to have the gtk main loop all contained within its own thread?
My daemon has a basic "while: True" main loop. So, I can't put gtk.run() in my main thread. My solution was to put the indicator code, along with gtk.run() in a separate thread, as such:
gtk.gdk.threads_init()
class IndicatorThread(Thread):
"Separate thread for gnome indicator icon"
def run(self):
self.ind = appindicator.Indicator("tracker-daemon", "gtg-panel",
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
menu = gtk.Menu()
self.ind.set_menu(menu)
self.running = True
gtk.main()
def stop(self):
if getattr(self, 'running', False):
gtk.main_quit()
This works for the most part, but my daemon hangs when I kill it or when I do a debug breakpoint using ipdb.set_trace().
Am I going about this all wrong? Is there no clean way to have the gtk main loop all contained within its own thread?