Skip to content
Browse files

switch from threading to gevent

  • Loading branch information...
1 parent 2e0f798 commit d142021f9335afae6a86e2141bd51b75c3a2ec7a @wraithan committed Apr 17, 2012
Showing with 26 additions and 19 deletions.
  1. +5 −0 python/HISTORY.rst
  2. +2 −2 python/setup.py
  3. +19 −17 python/zenircbot_api.py
View
5 python/HISTORY.rst
@@ -3,6 +3,11 @@
History
-------
+2.2.2 (2012-04-17)
+++++++++++++++++++
+
+* Switched to gevent instead of Thread to make killing services easier.
+
2.2.1 (2012-04-17)
++++++++++++++++++
View
4 python/setup.py
@@ -14,12 +14,12 @@
os.system('python setup.py sdist upload')
sys.exit()
-required = ['redis',]
+required = ['redis', 'gevent']
py_modules = ['zenircbot_api',]
setup(
name='zenircbot_api',
- version='2.2.1',
+ version='2.2.2',
description='API for ZenIRCBot',
long_description=open('README.rst').read() + '\n\n' +
open('HISTORY.rst').read(),
View
36 python/zenircbot_api.py
@@ -1,15 +1,17 @@
import json
-from threading import Thread
-
+import gevent
+from gevent import monkey
from redis import StrictRedis
+monkey.patch_all()
+
def load_config(name):
with open(name) as f:
return json.loads(f.read())
-__version__ = '2.2.1'
+__version__ = '2.2.2''
class ZenIRCBot(object):
@@ -50,20 +52,20 @@ def register_commands(self, service, commands):
self.send_admin_message(service + ' online!')
if commands:
def registration_reply(message, service, commands):
- if message['version'] == 1 and message['type'] == 'privmsg':
- if message['data']['message'] == "commands":
- for command in commands:
- self.send_privmsg(message['data']['sender'],
- "%s: %s - %s" % (
- service,
- command['name'],
- command['description']
- ))
- redis_sub = Thread(target=self.non_blocking_redis_subscribe,
- kwargs={'func': registration_reply,
- 'kwargs': {'service': service,
- 'commands': commands}})
- redis_sub.start()
+ if message['version'] == 1:
+ if message['type'] == 'directed_privmsg':
+ if message['data']['message'] == 'commands':
+ for command in commands:
+ self.send_privmsg(message['data']['sender'],
+ '%s: %s - %s' % (
+ service,
+ command['name'],
+ command['description']
+ ))
+ redis_sub = gevent.spawn(self.non_blocking_redis_subscribe,
+ func=registration_reply,
+ kwargs={'service': service,
+ 'commands': commands})
def get_redis_client(self):
return StrictRedis(host=self.host,

0 comments on commit d142021

Please sign in to comment.
Something went wrong with that request. Please try again.