From 6ba131af5cf6238fe4a4a702b38dfec2bb1292f9 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 25 Nov 2016 18:29:04 -0800 Subject: [PATCH] Warn when message queues are used without monkey patching --- socketio/kombu_manager.py | 14 ++++++++++++++ socketio/redis_manager.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/socketio/kombu_manager.py b/socketio/kombu_manager.py index 3895e8a..7d97e08 100644 --- a/socketio/kombu_manager.py +++ b/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) diff --git a/socketio/redis_manager.py b/socketio/redis_manager.py index e11ab97..3ed63e5 100644 --- a/socketio/redis_manager.py +++ b/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))