Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose the unfinished tasks variable #34

Merged
merged 3 commits into from Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions janus/__init__.py
Expand Up @@ -219,6 +219,11 @@ def qsize(self):
'''Return the approximate size of the queue (not reliable!).'''
return self._parent._qsize()

@property
def unfinished_tasks(self):
'''Return the number of unfinished tasks.'''
return self._parent._unfinished_tasks

def empty(self):
'''Return True if the queue is empty, False otherwise (not reliable!).

Expand Down Expand Up @@ -341,6 +346,11 @@ def qsize(self):
"""Number of items in the queue."""
return self._parent._qsize()

@property
def unfinished_tasks(self):
'''Return the number of unfinished tasks.'''
return self._parent._unfinished_tasks

@property
def maxsize(self):
"""Number of items allowed in the queue."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_mixed.py
Expand Up @@ -43,6 +43,20 @@ def test_maxsize_default(self):
q = janus.Queue(loop=self.loop)
self.assertIs(0, q.maxsize)

def test_unfinished(self):
q = janus.Queue(loop=self.loop)
self.assertEqual(q.sync_q.unfinished_tasks, 0)
self.assertEqual(q.async_q.unfinished_tasks, 0)
q.sync_q.put(1)
self.assertEqual(q.sync_q.unfinished_tasks, 1)
self.assertEqual(q.async_q.unfinished_tasks, 1)
q.sync_q.get()
self.assertEqual(q.sync_q.unfinished_tasks, 1)
self.assertEqual(q.async_q.unfinished_tasks, 1)
q.sync_q.task_done()
self.assertEqual(q.sync_q.unfinished_tasks, 0)
self.assertEqual(q.async_q.unfinished_tasks, 0)

def test_sync_put_async_get(self):
q = janus.Queue(loop=self.loop)

Expand Down