Improve clarity with keyword argument for block. Move nowait methods together.

This commit is contained in:
Raymond Hettinger 2012-01-09 06:02:08 +00:00
parent 143f51ade5
commit 61bd72924e
1 changed files with 9 additions and 9 deletions

View File

@ -145,14 +145,6 @@ class Queue:
self.unfinished_tasks += 1 self.unfinished_tasks += 1
self.not_empty.notify() self.not_empty.notify()
def put_nowait(self, item):
"""Put an item into the queue without blocking.
Only enqueue the item if a free slot is immediately available.
Otherwise raise the Full exception.
"""
return self.put(item, False)
def get(self, block=True, timeout=None): def get(self, block=True, timeout=None):
"""Remove and return an item from the queue. """Remove and return an item from the queue.
@ -184,13 +176,21 @@ class Queue:
self.not_full.notify() self.not_full.notify()
return item return item
def put_nowait(self, item):
"""Put an item into the queue without blocking.
Only enqueue the item if a free slot is immediately available.
Otherwise raise the Full exception.
"""
return self.put(item, block=False)
def get_nowait(self): def get_nowait(self):
"""Remove and return an item from the queue without blocking. """Remove and return an item from the queue without blocking.
Only get an item if one is immediately available. Otherwise Only get an item if one is immediately available. Otherwise
raise the Empty exception. raise the Empty exception.
""" """
return self.get(False) return self.get(block=False)
# Override these methods to implement other queue organizations # Override these methods to implement other queue organizations
# (e.g. stack or priority queue). # (e.g. stack or priority queue).