Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

switch from threading to gevent

  • Loading branch information...
commit d142021f9335afae6a86e2141bd51b75c3a2ec7a 1 parent 2e0f798
Wraithan (Chris McDonald) authored
5 python/HISTORY.rst
Source Rendered
@@ -3,6 +3,11 @@
3 3 History
4 4 -------
5 5
  6 +2.2.2 (2012-04-17)
  7 +++++++++++++++++++
  8 +
  9 +* Switched to gevent instead of Thread to make killing services easier.
  10 +
6 11 2.2.1 (2012-04-17)
7 12 ++++++++++++++++++
8 13
4 python/setup.py
@@ -14,12 +14,12 @@
14 14 os.system('python setup.py sdist upload')
15 15 sys.exit()
16 16
17   -required = ['redis',]
  17 +required = ['redis', 'gevent']
18 18 py_modules = ['zenircbot_api',]
19 19
20 20 setup(
21 21 name='zenircbot_api',
22   - version='2.2.1',
  22 + version='2.2.2',
23 23 description='API for ZenIRCBot',
24 24 long_description=open('README.rst').read() + '\n\n' +
25 25 open('HISTORY.rst').read(),
36 python/zenircbot_api.py
... ... @@ -1,15 +1,17 @@
1 1 import json
2   -from threading import Thread
3   -
  2 +import gevent
  3 +from gevent import monkey
4 4 from redis import StrictRedis
5 5
6 6
  7 +monkey.patch_all()
  8 +
7 9 def load_config(name):
8 10 with open(name) as f:
9 11 return json.loads(f.read())
10 12
11 13
12   -__version__ = '2.2.1'
  14 +__version__ = '2.2.2''
13 15
14 16
15 17 class ZenIRCBot(object):
@@ -50,20 +52,20 @@ def register_commands(self, service, commands):
50 52 self.send_admin_message(service + ' online!')
51 53 if commands:
52 54 def registration_reply(message, service, commands):
53   - if message['version'] == 1 and message['type'] == 'privmsg':
54   - if message['data']['message'] == "commands":
55   - for command in commands:
56   - self.send_privmsg(message['data']['sender'],
57   - "%s: %s - %s" % (
58   - service,
59   - command['name'],
60   - command['description']
61   - ))
62   - redis_sub = Thread(target=self.non_blocking_redis_subscribe,
63   - kwargs={'func': registration_reply,
64   - 'kwargs': {'service': service,
65   - 'commands': commands}})
66   - redis_sub.start()
  55 + if message['version'] == 1:
  56 + if message['type'] == 'directed_privmsg':
  57 + if message['data']['message'] == 'commands':
  58 + for command in commands:
  59 + self.send_privmsg(message['data']['sender'],
  60 + '%s: %s - %s' % (
  61 + service,
  62 + command['name'],
  63 + command['description']
  64 + ))
  65 + redis_sub = gevent.spawn(self.non_blocking_redis_subscribe,
  66 + func=registration_reply,
  67 + kwargs={'service': service,
  68 + 'commands': commands})
67 69
68 70 def get_redis_client(self):
69 71 return StrictRedis(host=self.host,

0 comments on commit d142021

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