mirror of
https://github.com/0intro/wmii
synced 2024-11-22 05:42:05 +03:00
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:
parent
ea0e1bbe5d
commit
d4d8a6b891
@ -108,7 +108,7 @@ class Events():
|
||||
|
||||
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.
|
||||
Continues so long as #alive is True.
|
||||
"""
|
||||
|
@ -1,16 +1,13 @@
|
||||
from threading import Thread
|
||||
from pygmi.util import call
|
||||
|
||||
__all__ = 'Menu', 'ClickMenu'
|
||||
|
||||
def inthread(fn, action):
|
||||
def run():
|
||||
res = fn()
|
||||
if action:
|
||||
return action(res)
|
||||
return res
|
||||
return run()
|
||||
# Bug.
|
||||
t = Thread(target=run)
|
||||
def inthread(args, action, **kwargs):
|
||||
fn = lambda: call(*args, **kwargs)
|
||||
if not action:
|
||||
return fn()
|
||||
t = Thread(target=lambda: action(fn()))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
@ -27,14 +24,12 @@ class Menu(object):
|
||||
choices = self.choices
|
||||
if callable(choices):
|
||||
choices = choices()
|
||||
def act():
|
||||
args = ['wimenu']
|
||||
if self.histfile:
|
||||
args += ['-h', self.histfile]
|
||||
if self.nhist:
|
||||
args += ['-n', self.nhist]
|
||||
return call(*map(str, args), input='\n'.join(choices))
|
||||
return inthread(act, self.action)
|
||||
args = ['wimenu']
|
||||
if self.histfile:
|
||||
args += ['-h', self.histfile]
|
||||
if self.nhist:
|
||||
args += ['-n', self.nhist]
|
||||
return inthread(map(str, args), self.action, input='\n'.join(choices))
|
||||
call = __call__
|
||||
|
||||
class ClickMenu(object):
|
||||
@ -49,13 +44,11 @@ class ClickMenu(object):
|
||||
choices = self.choices
|
||||
if callable(choices):
|
||||
choices = choices()
|
||||
def act():
|
||||
args = ['wmii9menu']
|
||||
if self.prev:
|
||||
args += ['-i', self.prev]
|
||||
args += ['--'] + list(choices)
|
||||
return call(*map(str, args)).replace('\n', '')
|
||||
return inthread(act, self.action)
|
||||
args = ['wmii9menu']
|
||||
if self.prev:
|
||||
args += ['-i', self.prev]
|
||||
args += ['--'] + list(choices)
|
||||
return inthread(map(str, args), self.action)
|
||||
call = __call__
|
||||
|
||||
# vim:se sts=4 sw=4 et:
|
||||
|
@ -5,5 +5,8 @@ for p in os.environ.get("WMII_CONFPATH", "").split(':'):
|
||||
path += [p, p + '/python']
|
||||
sys.path = path + sys.path
|
||||
|
||||
import pygmi
|
||||
from pygmi import events
|
||||
import wmiirc
|
||||
|
||||
events.loop()
|
||||
|
||||
|
@ -304,6 +304,4 @@ for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]:
|
||||
except Exception, e:
|
||||
traceback.print_exc(sys.stdout)
|
||||
|
||||
events.loop()
|
||||
|
||||
# vim:se sts=4 sw=4 et:
|
||||
|
Loading…
Reference in New Issue
Block a user