|
9 | 9 | * :class:`Lock` |
10 | 10 | * :class:`Event` |
11 | 11 | * :class:`Condition` |
12 | | -* :class:`Semaphore` |
13 | | -* :class:`BoundedSemaphore` |
14 | 12 |
|
15 | | -Queues: |
| 13 | +Semaphores: |
16 | 14 |
|
17 | | -* :class:`Queue` |
18 | | -* :class:`PriorityQueue` |
19 | | -* :class:`LifoQueue` |
20 | | -* :class:`JoinableQueue` |
| 15 | +* :class:`Semaphore` |
| 16 | +* :class:`BoundedSemaphore` |
21 | 17 |
|
22 | | -asyncio locks and queues API were designed to be close to classes of the |
23 | | -:mod:`threading` module (:class:`~threading.Lock`, :class:`~threading.Event`, |
| 18 | +asyncio lock API was designed to be close to classes of the :mod:`threading` |
| 19 | +module (:class:`~threading.Lock`, :class:`~threading.Event`, |
24 | 20 | :class:`~threading.Condition`, :class:`~threading.Semaphore`, |
25 | | -:class:`~threading.BoundedSemaphore`) and the :mod:`queue` module |
26 | | -(:class:`~queue.Queue`, :class:`~queue.PriorityQueue`, |
27 | | -:class:`~queue.LifoQueue`), but they have no *timeout* parameter. The |
| 21 | +:class:`~threading.BoundedSemaphore`), but it has no *timeout* parameter. The |
28 | 22 | :func:`asyncio.wait_for` function can be used to cancel a task after a timeout. |
29 | 23 |
|
30 | 24 | Locks |
@@ -290,157 +284,3 @@ BoundedSemaphore |
290 | 284 | This raises :exc:`ValueError` in :meth:`~Semaphore.release` if it would |
291 | 285 | increase the value above the initial value. |
292 | 286 |
|
293 | | - |
294 | | -Queues |
295 | | ------- |
296 | | - |
297 | | -Queue |
298 | | -^^^^^ |
299 | | - |
300 | | -.. class:: Queue(maxsize=0, \*, loop=None) |
301 | | - |
302 | | - A queue, useful for coordinating producer and consumer coroutines. |
303 | | - |
304 | | - If *maxsize* is less than or equal to zero, the queue size is infinite. If |
305 | | - it is an integer greater than ``0``, then ``yield from put()`` will block |
306 | | - when the queue reaches *maxsize*, until an item is removed by :meth:`get`. |
307 | | - |
308 | | - Unlike the standard library :mod:`queue`, you can reliably know this Queue's |
309 | | - size with :meth:`qsize`, since your single-threaded asyncio application won't |
310 | | - be interrupted between calling :meth:`qsize` and doing an operation on the |
311 | | - Queue. |
312 | | - |
313 | | - .. versionchanged:: 3.4.3 |
314 | | - New :meth:`join` and :meth:`task_done` methods. |
315 | | - |
316 | | - .. method:: empty() |
317 | | - |
318 | | - Return ``True`` if the queue is empty, ``False`` otherwise. |
319 | | - |
320 | | - .. method:: full() |
321 | | - |
322 | | - Return ``True`` if there are :attr:`maxsize` items in the queue. |
323 | | - |
324 | | - .. note:: |
325 | | - |
326 | | - If the Queue was initialized with ``maxsize=0`` (the default), then |
327 | | - :meth:`full()` is never ``True``. |
328 | | - |
329 | | - .. coroutinemethod:: get() |
330 | | - |
331 | | - Remove and return an item from the queue. If queue is empty, wait until |
332 | | - an item is available. |
333 | | - |
334 | | - This method is a :ref:`coroutine <coroutine>`. |
335 | | - |
336 | | - .. seealso:: |
337 | | - |
338 | | - The :meth:`empty` method. |
339 | | - |
340 | | - .. method:: get_nowait() |
341 | | - |
342 | | - Remove and return an item from the queue. |
343 | | - |
344 | | - Return an item if one is immediately available, else raise |
345 | | - :exc:`QueueEmpty`. |
346 | | - |
347 | | - .. coroutinemethod:: join() |
348 | | - |
349 | | - Block until all items in the queue have been gotten and processed. |
350 | | - |
351 | | - The count of unfinished tasks goes up whenever an item is added to the |
352 | | - queue. The count goes down whenever a consumer thread calls |
353 | | - :meth:`task_done` to indicate that the item was retrieved and all work on |
354 | | - it is complete. When the count of unfinished tasks drops to zero, |
355 | | - :meth:`join` unblocks. |
356 | | - |
357 | | - This method is a :ref:`coroutine <coroutine>`. |
358 | | - |
359 | | - .. versionadded:: 3.4.3 |
360 | | - |
361 | | - .. coroutinemethod:: put(item) |
362 | | - |
363 | | - Put an item into the queue. If the queue is full, wait until a free slot |
364 | | - is available before adding item. |
365 | | - |
366 | | - This method is a :ref:`coroutine <coroutine>`. |
367 | | - |
368 | | - .. seealso:: |
369 | | - |
370 | | - The :meth:`full` method. |
371 | | - |
372 | | - .. method:: put_nowait(item) |
373 | | - |
374 | | - Put an item into the queue without blocking. |
375 | | - |
376 | | - If no free slot is immediately available, raise :exc:`QueueFull`. |
377 | | - |
378 | | - .. method:: qsize() |
379 | | - |
380 | | - Number of items in the queue. |
381 | | - |
382 | | - .. method:: task_done() |
383 | | - |
384 | | - Indicate that a formerly enqueued task is complete. |
385 | | - |
386 | | - Used by queue consumers. For each :meth:`~Queue.get` used to fetch a task, a |
387 | | - subsequent call to :meth:`task_done` tells the queue that the processing |
388 | | - on the task is complete. |
389 | | - |
390 | | - If a :meth:`join` is currently blocking, it will resume when all items |
391 | | - have been processed (meaning that a :meth:`task_done` call was received |
392 | | - for every item that had been :meth:`~Queue.put` into the queue). |
393 | | - |
394 | | - Raises :exc:`ValueError` if called more times than there were items |
395 | | - placed in the queue. |
396 | | - |
397 | | - .. versionadded:: 3.4.3 |
398 | | - |
399 | | - .. attribute:: maxsize |
400 | | - |
401 | | - Number of items allowed in the queue. |
402 | | - |
403 | | - |
404 | | -PriorityQueue |
405 | | -^^^^^^^^^^^^^ |
406 | | - |
407 | | -.. class:: PriorityQueue |
408 | | - |
409 | | - A subclass of :class:`Queue`; retrieves entries in priority order (lowest |
410 | | - first). |
411 | | - |
412 | | - Entries are typically tuples of the form: (priority number, data). |
413 | | - |
414 | | - |
415 | | -LifoQueue |
416 | | -^^^^^^^^^ |
417 | | - |
418 | | -.. class:: LifoQueue |
419 | | - |
420 | | - A subclass of :class:`Queue` that retrieves most recently added entries |
421 | | - first. |
422 | | - |
423 | | - |
424 | | -JoinableQueue |
425 | | -^^^^^^^^^^^^^ |
426 | | - |
427 | | -.. class:: JoinableQueue |
428 | | - |
429 | | - Deprecated alias for :class:`Queue`. |
430 | | - |
431 | | - .. deprecated:: 3.4.3 |
432 | | - |
433 | | - |
434 | | -Exceptions |
435 | | -^^^^^^^^^^ |
436 | | - |
437 | | -.. exception:: QueueEmpty |
438 | | - |
439 | | - Exception raised when the :meth:`~Queue.get_nowait` method is called on a |
440 | | - :class:`Queue` object which is empty. |
441 | | - |
442 | | - |
443 | | -.. exception:: QueueFull |
444 | | - |
445 | | - Exception raised when the :meth:`~Queue.put_nowait` method is called on a |
446 | | - :class:`Queue` object which is full. |
0 commit comments