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

Method put

Lib/queue.py:137–175  ·  view source on GitHub ↗

Put an item into the queue. If optional args 'block' is true and 'timeout' is None (the default), block if necessary until a free slot is available. If 'timeout' is a non-negative number, it blocks at most 'timeout' seconds and raises the Full exception if no free sl

(self, item, block=True, timeout=None)

Source from the content-addressed store, hash-verified

135 return 0 < self.maxsize <= self._qsize()
136
137 def put(self, item, block=True, timeout=None):
138 ''&#x27;Put an item into the queue.
139
140 If optional args 'block' is true and 'timeout' is None (the default),
141 block if necessary until a free slot is available. If 'timeout' is
142 a non-negative number, it blocks at most 'timeout' seconds and raises
143 the Full exception if no free slot was available within that time.
144 Otherwise ('block' is false), put an item on the queue if a free slot
145 is immediately available, else raise the Full exception ('timeout'
146 is ignored in that case).
147
148 Raises ShutDown if the queue has been shut down.
149 ''&#x27;
150 with self.not_full:
151 if self.is_shutdown:
152 raise ShutDown
153 if self.maxsize > 0:
154 if not block:
155 if self._qsize() >= self.maxsize:
156 raise Full
157 elif timeout is None:
158 while self._qsize() >= self.maxsize:
159 self.not_full.wait()
160 if self.is_shutdown:
161 raise ShutDown
162 elif timeout < 0:
163 raise ValueError("'timeout' must be a non-negative number")
164 else:
165 endtime = time() + timeout
166 while self._qsize() >= self.maxsize:
167 remaining = endtime - time()
168 if remaining <= 0.0:
169 raise Full
170 self.not_full.wait(remaining)
171 if self.is_shutdown:
172 raise ShutDown
173 self._put(item)
174 self.unfinished_tasks += 1
175 self.not_empty.notify()
176
177 def get(self, block=True, timeout=None):
178 ''&#x27;Remove and return an item from the queue.

Callers 7

testFunction · 0.95
put_nowaitMethod · 0.95
workerFunction · 0.45
optimizeFunction · 0.45
do_singleFunction · 0.45
bench_parallelFunction · 0.45
thread_runFunction · 0.45

Calls 5

_qsizeMethod · 0.95
_putMethod · 0.95
timeClass · 0.90
waitMethod · 0.45
notifyMethod · 0.45

Tested by

no test coverage detected