Skip to content

Commit 81c4622

Browse files
authored
Merge pull request #75 from vlanse/master
async_q.join() sometimes never return
2 parents 69d4155 + 78cde4a commit 81c4622

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

janus/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ def put(self, item, block=True, timeout=None):
277277
if remaining <= 0.0:
278278
raise SyncQueueFull
279279
self._parent._sync_not_full.wait(remaining)
280-
self._parent._put(item)
281-
self._parent._unfinished_tasks += 1
280+
self._parent._put_internal(item)
282281
self._parent._sync_not_empty.notify()
283282
self._parent._notify_async_not_empty(threadsafe=True)
284283

tests/test_mixed.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ def go():
7878
for i in range(3):
7979
self.loop.run_until_complete(go())
8080

81+
def test_sync_put_async_join(self):
82+
q = janus.Queue(loop=self.loop)
83+
84+
for i in range(5):
85+
q.sync_q.put(i)
86+
87+
@asyncio.coroutine
88+
def do_work():
89+
yield from asyncio.sleep(1, loop=self.loop)
90+
while True:
91+
yield from q.async_q.get()
92+
q.async_q.task_done()
93+
94+
task = self.loop.create_task(do_work())
95+
96+
@asyncio.coroutine
97+
def wait_for_empty_queue():
98+
yield from q.async_q.join()
99+
task.cancel()
100+
101+
self.loop.run_until_complete(wait_for_empty_queue())
102+
81103
def test_async_put_sync_get(self):
82104
q = janus.Queue(loop=self.loop)
83105

0 commit comments

Comments
 (0)