Properly fix problem fixed in last commit. Cleanup some stuff in the process.

Update issue #132
Status: Fixed
This is a very strange issue. It turns out that subprocess
won't work from non-main threads while a module is being
imported. Since the wmiirc entered its event loop rather than
returning, it was causing problems. I suspect it was also the
cause of the stack traces being printed at interperater shutdown.
This commit is contained in:
Kris Maglione 2009-10-17 21:52:29 -04:00
parent ea0e1bbe5d
commit d4d8a6b891
4 changed files with 22 additions and 28 deletions

View File

@ -108,7 +108,7 @@ class Events():
def loop(self): def loop(self):
""" """
Enters teh event loop, reading lines from wmii's '/event' Enters the event loop, reading lines from wmii's '/event'
and dispatching them, via #dispatch, to event handlers. and dispatching them, via #dispatch, to event handlers.
Continues so long as #alive is True. Continues so long as #alive is True.
""" """

View File

@ -1,16 +1,13 @@
from threading import Thread
from pygmi.util import call from pygmi.util import call
__all__ = 'Menu', 'ClickMenu' __all__ = 'Menu', 'ClickMenu'
def inthread(fn, action): def inthread(args, action, **kwargs):
def run(): fn = lambda: call(*args, **kwargs)
res = fn() if not action:
if action: return fn()
return action(res) t = Thread(target=lambda: action(fn()))
return res
return run()
# Bug.
t = Thread(target=run)
t.daemon = True t.daemon = True
t.start() t.start()
@ -27,14 +24,12 @@ class Menu(object):
choices = self.choices choices = self.choices
if callable(choices): if callable(choices):
choices = choices() choices = choices()
def act():
args = ['wimenu'] args = ['wimenu']
if self.histfile: if self.histfile:
args += ['-h', self.histfile] args += ['-h', self.histfile]
if self.nhist: if self.nhist:
args += ['-n', self.nhist] args += ['-n', self.nhist]
return call(*map(str, args), input='\n'.join(choices)) return inthread(map(str, args), self.action, input='\n'.join(choices))
return inthread(act, self.action)
call = __call__ call = __call__
class ClickMenu(object): class ClickMenu(object):
@ -49,13 +44,11 @@ class ClickMenu(object):
choices = self.choices choices = self.choices
if callable(choices): if callable(choices):
choices = choices() choices = choices()
def act():
args = ['wmii9menu'] args = ['wmii9menu']
if self.prev: if self.prev:
args += ['-i', self.prev] args += ['-i', self.prev]
args += ['--'] + list(choices) args += ['--'] + list(choices)
return call(*map(str, args)).replace('\n', '') return inthread(map(str, args), self.action)
return inthread(act, self.action)
call = __call__ call = __call__
# vim:se sts=4 sw=4 et: # vim:se sts=4 sw=4 et:

View File

@ -5,5 +5,8 @@ for p in os.environ.get("WMII_CONFPATH", "").split(':'):
path += [p, p + '/python'] path += [p, p + '/python']
sys.path = path + sys.path sys.path = path + sys.path
import pygmi from pygmi import events
import wmiirc import wmiirc
events.loop()

View File

@ -304,6 +304,4 @@ for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]:
except Exception, e: except Exception, e:
traceback.print_exc(sys.stdout) traceback.print_exc(sys.stdout)
events.loop()
# vim:se sts=4 sw=4 et: # vim:se sts=4 sw=4 et: