@@ -171,13 +171,13 @@ def full(self):
171171 def qsize (self ):
172172 return _queues .get_count (self ._id )
173173
174- def put (self , obj , timeout = None , * ,
174+ def put (self , obj , block = True , timeout = None , * ,
175175 unbounditems = None ,
176176 _delay = 10 / 1000 , # 10 milliseconds
177177 ):
178178 """Add the object to the queue.
179179
180- This blocks while the queue is full.
180+ If "block" is true, this blocks while the queue is full.
181181
182182 For most objects, the object received through Queue.get() will
183183 be a new one, equivalent to the original and not sharing any
@@ -210,6 +210,8 @@ def put(self, obj, timeout=None, *,
210210 If "unbounditems" is UNBOUND then it is returned by get() in place
211211 of the unbound item.
212212 """
213+ if not block :
214+ return self .put_nowait (obj , unbounditems = unbounditems )
213215 if unbounditems is None :
214216 unboundop = - 1
215217 else :
@@ -236,17 +238,19 @@ def put_nowait(self, obj, *, unbounditems=None):
236238 unboundop , = _serialize_unbound (unbounditems )
237239 _queues .put (self ._id , obj , unboundop )
238240
239- def get (self , timeout = None , * ,
241+ def get (self , block = True , timeout = None , * ,
240242 _delay = 10 / 1000 , # 10 milliseconds
241243 ):
242244 """Return the next object from the queue.
243245
244- This blocks while the queue is empty.
246+ If "block" is true, this blocks while the queue is empty.
245247
246248 If the next item's original interpreter has been destroyed
247249 then the "next object" is determined by the value of the
248250 "unbounditems" argument to put().
249251 """
252+ if not block :
253+ return self .get_nowait ()
250254 if timeout is not None :
251255 timeout = int (timeout )
252256 if timeout < 0 :
0 commit comments