Browse Source

Warn when message queues are used without monkey patching

pull/62/merge
Miguel Grinberg 8 years ago
parent
commit
6ba131af5c
  1. 14
      socketio/kombu_manager.py
  2. 14
      socketio/redis_manager.py

14
socketio/kombu_manager.py

@ -47,6 +47,20 @@ class KombuManager(PubSubManager): # pragma: no cover
self.url = url
self.producer = self._producer()
def initialize(self, server):
super(KombuManager, self).initialize(server)
monkey_patched = True
if server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket')
elif 'gevent' in 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)
def _connection(self):
return kombu.Connection(self.url)

14
socketio/redis_manager.py

@ -43,6 +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)
monkey_patched = True
if server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket')
elif 'gevent' in 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)
def _publish(self, data):
return self.redis.publish(self.channel, pickle.dumps(data))

Loading…
Cancel
Save