@@ -170,13 +170,13 @@ def full(self):
170170 def qsize (self ):
171171 return _queues .get_count (self ._id )
172172
173- def put (self , obj , timeout = None , * ,
173+ def put (self , obj , block = True , timeout = None , * ,
174174 unbounditems = None ,
175175 _delay = 10 / 1000 , # 10 milliseconds
176176 ):
177177 """Add the object to the queue.
178178
179- This blocks while the queue is full.
179+ If "block" is true, this blocks while the queue is full.
180180
181181 For most objects, the object received through Queue.get() will
182182 be a new one, equivalent to the original and not sharing any
@@ -209,6 +209,8 @@ def put(self, obj, timeout=None, *,
209209 If "unbounditems" is UNBOUND then it is returned by get() in place
210210 of the unbound item.
211211 """
212+ if not block :
213+ return self .put_nowait (obj , unbounditems = unbounditems )
212214 if unbounditems is None :
213215 unboundop = - 1
214216 else :
@@ -235,17 +237,19 @@ def put_nowait(self, obj, *, unbounditems=None):
235237 unboundop , = _serialize_unbound (unbounditems )
236238 _queues .put (self ._id , obj , unboundop )
237239
238- def get (self , timeout = None , * ,
240+ def get (self , block = True , timeout = None , * ,
239241 _delay = 10 / 1000 , # 10 milliseconds
240242 ):
241243 """Return the next object from the queue.
242244
243- This blocks while the queue is empty.
245+ If "block" is true, this blocks while the queue is empty.
244246
245247 If the next item's original interpreter has been destroyed
246248 then the "next object" is determined by the value of the
247249 "unbounditems" argument to put().
248250 """
251+ if not block :
252+ return self .get_nowait ()
249253 if timeout is not None :
250254 timeout = int (timeout )
251255 if timeout < 0 :
0 commit comments