Skip to content

Commit

Permalink
Fixed initialize() method in PubSubManager subclasses
Browse files Browse the repository at this point in the history
Fixes #406
  • Loading branch information
miguelgrinberg committed Feb 15, 2017
1 parent edbbbf2 commit 5e1391d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
13 changes: 7 additions & 6 deletions socketio/kombu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ def __init__(self, url='amqp://guest:guest@localhost:5672//',
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)
Expand Down
13 changes: 7 additions & 6 deletions socketio/redis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ def __init__(self, url='redis://localhost:6379/0', channel='socketio',
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))
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ basepython =
pypy: pypy

[testenv:flake8]
basepython=python
basepython=python3.6
deps=
flake8
commands=
Expand All @@ -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
Expand Down

0 comments on commit 5e1391d

Please sign in to comment.