[hackers] [wmii] Properly fix problem fixed in last commit. Cleanup some stuff in the process. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sun, 18 Oct 2009 01:52:53 +0000 (UTC)

changeset: 2555:c12cd18e53e2
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Oct 17 21:52:29 2009 -0400
files: alternative_wmiircs/python/pygmi/event.py alternative_wmiircs/python/pygmi/menu.py alternative_wmiircs/python/wmiirc alternative_wmiircs/python/wmiirc.py
description:
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.

diff -r e7dccbb4544a -r c12cd18e53e2 alternative_wmiircs/python/pygmi/event.py
--- a/alternative_wmiircs/python/pygmi/event.py Sat Oct 17 19:38:31 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/event.py Sat Oct 17 21:52:29 2009 -0400
@@ -108,7 +108,7 @@
 
     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.
         """
diff -r e7dccbb4544a -r c12cd18e53e2 alternative_wmiircs/python/pygmi/menu.py
--- a/alternative_wmiircs/python/pygmi/menu.py Sat Oct 17 19:38:31 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/menu.py Sat Oct 17 21:52:29 2009 -0400
@@ -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 @@
             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 @@
             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:
diff -r e7dccbb4544a -r c12cd18e53e2 alternative_wmiircs/python/wmiirc
--- a/alternative_wmiircs/python/wmiirc Sat Oct 17 19:38:31 2009 -0400
+++ b/alternative_wmiircs/python/wmiirc Sat Oct 17 21:52:29 2009 -0400
@@ -5,5 +5,8 @@
     path += [p, p + '/python']
 sys.path = path + sys.path
 
-import pygmi
+from pygmi import events
 import wmiirc
+
+events.loop()
+
diff -r e7dccbb4544a -r c12cd18e53e2 alternative_wmiircs/python/wmiirc.py
--- a/alternative_wmiircs/python/wmiirc.py Sat Oct 17 19:38:31 2009 -0400
+++ b/alternative_wmiircs/python/wmiirc.py Sat Oct 17 21:52:29 2009 -0400
@@ -304,6 +304,4 @@
     except Exception, e:
         traceback.print_exc(sys.stdout)
 
-events.loop()
-
 # vim:se sts=4 sw=4 et:
Received on Sun Oct 18 2009 - 01:52:53 UTC

This archive was generated by hypermail 2.2.0 : Sun Oct 18 2009 - 02:00:07 UTC