Skip to content

Commit 0c35757

Browse files
Use separate read and write Kombu connections
Eventlet does not like file handles to be shared among greenlets. Using an independent connection in the listening thread addresses this problem. (fixes #13)
1 parent 155fd5b commit 0c35757

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

socketio/kombu_manager.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,24 @@ def __init__(self, url='amqp://guest:guest@localhost:5672//',
4343
raise RuntimeError('Kombu package is not installed '
4444
'(Run "pip install kombu" in your '
4545
'virtualenv).')
46-
self.kombu = kombu.Connection(url)
47-
self.exchange = kombu.Exchange(channel, type='fanout', durable=False)
48-
self.queue = kombu.Queue(str(uuid.uuid4()), self.exchange)
49-
super(KombuManager, self).__init__(channel=channel,
50-
write_only=write_only)
46+
super(KombuManager, self).__init__(channel=channel)
47+
self.url = url
48+
self.writer_conn = kombu.Connection(self.url)
49+
self.writer_queue = self._queue(self.writer_conn)
50+
51+
def _queue(self, conn=None):
52+
exchange = kombu.Exchange(self.channel, type='fanout', durable=False)
53+
queue = kombu.Queue(str(uuid.uuid4()), exchange)
54+
return queue
5155

5256
def _publish(self, data):
53-
with self.kombu.SimpleQueue(self.queue) as queue:
57+
with self.writer_conn.SimpleQueue(self.writer_queue) as queue:
5458
queue.put(pickle.dumps(data))
5559

5660
def _listen(self):
57-
with self.kombu.SimpleQueue(self.queue) as queue:
61+
reader_conn = kombu.Connection(self.url)
62+
reader_queue = self._queue(reader_conn)
63+
with reader_conn.SimpleQueue(reader_queue) as queue:
5864
while True:
5965
message = queue.get(block=True)
6066
message.ack()

0 commit comments

Comments
 (0)