MCPcopy Index your code
hub / github.com/python/cpython / put

Method put

Lib/concurrent/interpreters/_queues.py:173–231  ·  view source on GitHub ↗

Add the object to the queue. If "block" is true, this blocks while the queue is full. For most objects, the object received through Queue.get() will be a new one, equivalent to the original and not sharing any actual underlying data. The notable exceptions include

(self, obj, block=True, timeout=None, *,
            unbounditems=None,
            _delay=10 / 1000,  # 10 milliseconds
            )

Source from the content-addressed store, hash-verified

171 return _queues.get_count(self._id)
172
173 def put(self, obj, block=True, timeout=None, *,
174 unbounditems=None,
175 _delay=10 / 1000, # 10 milliseconds
176 ):
177 """Add the object to the queue.
178
179 If "block" is true, this blocks while the queue is full.
180
181 For most objects, the object received through Queue.get() will
182 be a new one, equivalent to the original and not sharing any
183 actual underlying data. The notable exceptions include
184 cross-interpreter types (like Queue) and memoryview, where the
185 underlying data is actually shared. Furthermore, some types
186 can be sent through a queue more efficiently than others. This
187 group includes various immutable types like int, str, bytes, and
188 tuple (if the items are likewise efficiently shareable). See interpreters.is_shareable().
189
190 "unbounditems" controls the behavior of Queue.get() for the given
191 object if the current interpreter (calling put()) is later
192 destroyed.
193
194 If "unbounditems" is None (the default) then it uses the
195 queue's default, set with create_queue(),
196 which is usually UNBOUND.
197
198 If "unbounditems" is UNBOUND_ERROR then get() will raise an
199 ItemInterpreterDestroyed exception if the original interpreter
200 has been destroyed. This does not otherwise affect the queue;
201 the next call to put() will work like normal, returning the next
202 item in the queue.
203
204 If "unbounditems" is UNBOUND_REMOVE then the item will be removed
205 from the queue as soon as the original interpreter is destroyed.
206 Be aware that this will introduce an imbalance between put()
207 and get() calls.
208
209 If "unbounditems" is UNBOUND then it is returned by get() in place
210 of the unbound item.
211 """
212 if not block:
213 return self.put_nowait(obj, unbounditems=unbounditems)
214 if unbounditems is None:
215 unboundop = -1
216 else:
217 unboundop, = _serialize_unbound(unbounditems)
218 if timeout is not None:
219 timeout = int(timeout)
220 if timeout < 0:
221 raise ValueError(f'timeout value must be non-negative')
222 end = time.time() + timeout
223 while True:
224 try:
225 _queues.put(self._id, obj, unboundop)
226 except QueueFull:
227 if timeout is not None and time.time() >= end:
228 raise # re-raise
229 time.sleep(_delay)
230 else:

Callers 11

put_nowaitMethod · 0.45
do_callFunction · 0.45
_python_exitFunction · 0.45
_workerFunction · 0.45
submitMethod · 0.45
weakref_cbMethod · 0.45
shutdownMethod · 0.45
_sendback_resultFunction · 0.45
_process_workerFunction · 0.45
submitMethod · 0.45

Calls 4

put_nowaitMethod · 0.95
_serialize_unboundFunction · 0.70
timeMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected