Browse Source

Fixed initialize() method in PubSubManager subclasses

Fixes #406
pull/117/head
Miguel Grinberg 8 years ago
parent
commit
5e1391d80e
  1. 13
      socketio/kombu_manager.py
  2. 13
      socketio/redis_manager.py
  3. 4
      tox.ini

13
socketio/kombu_manager.py

@ -47,19 +47,20 @@ class KombuManager(PubSubManager): # pragma: no cover
self.url = url
self.producer = self._producer()
def initialize(self, server):
super(KombuManager, self).initialize(server)
def initialize(self):
super(KombuManager, self).initialize()
monkey_patched = True
if server.async_mode == 'eventlet':
if self.server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket')
elif 'gevent' in server.async_mode:
elif 'gevent' in self.server.async_mode:
from gevent.monkey import is_module_patched
monkey_patched = is_module_patched('socket')
if not monkey_patched:
raise RuntimeError('Redis requires a monkey patched socket '
'library to work with ' + server.async_mode)
raise RuntimeError(
'Redis requires a monkey patched socket library to work '
'with ' + self.server.async_mode)
def _connection(self):
return kombu.Connection(self.url)

13
socketio/redis_manager.py

@ -43,19 +43,20 @@ class RedisManager(PubSubManager): # pragma: no cover
super(RedisManager, self).__init__(channel=channel,
write_only=write_only)
def initialize(self, server):
super(RedisManager, self).initialize(server)
def initialize(self):
super(RedisManager, self).initialize()
monkey_patched = True
if server.async_mode == 'eventlet':
if self.server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket')
elif 'gevent' in server.async_mode:
elif 'gevent' in self.server.async_mode:
from gevent.monkey import is_module_patched
monkey_patched = is_module_patched('socket')
if not monkey_patched:
raise RuntimeError('Redis requires a monkey patched socket '
'library to work with ' + server.async_mode)
raise RuntimeError(
'Redis requires a monkey patched socket library to work '
'with ' + self.server.async_mode)
def _publish(self, data):
return self.redis.publish(self.channel, pickle.dumps(data))

4
tox.ini

@ -18,7 +18,7 @@ basepython =
pypy: pypy
[testenv:flake8]
basepython=python
basepython=python3.6
deps=
flake8
commands=
@ -35,7 +35,7 @@ commands=
make html
[testenv:coverage]
basepython=python
basepython=python3.6
commands=
coverage run --branch --source=socketio setup.py test
coverage html

Loading…
Cancel
Save