File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/tornado/__pycache__/queues.cpython-310.pyc
Back
o �h�0 � @ s$ d Z ddlZddlZddlZddlmZmZ ddlmZm Z ddl mZ ddlm Z mZmZmZmZ ddlZejrCddlmZmZmZ ed�Zg d �ZG d d� de�ZG dd � d e�Zdede deejf ddfdd�ZG dd� dee �ZG dd� dee �ZG dd� de�Z G dd� de�Z!dS )a� Asynchronous queues for coroutines. These classes are very similar to those provided in the standard library's `asyncio package <https://docs.python.org/3/library/asyncio-queue.html>`_. .. warning:: Unlike the standard library's `queue` module, the classes defined here are *not* thread-safe. To use these queues from another thread, use `.IOLoop.add_callback` to transfer control to the `.IOLoop` thread before calling any queue methods. � N)�gen�ioloop)�Future�"future_set_result_unless_cancelled)�Event)�Union�TypeVar�Generic� Awaitable�Optional)�Deque�Tuple�Any�_T)�Queue� PriorityQueue� LifoQueue� QueueFull� QueueEmptyc @ � e Zd ZdZdS )r z:Raised by `.Queue.get_nowait` when the queue has no items.N��__name__� __module__�__qualname__�__doc__� r r �D/usr/local/CyberPanel/lib/python3.10/site-packages/tornado/queues.pyr / � r c @ r )r zBRaised by `.Queue.put_nowait` when a queue is at its maximum size.Nr r r r r r 5 r r �future�timeout�returnc sD |r d� fdd�}t j�� ���||��� ���fdd�� d S d S )Nr c s � � � s � �t�� � d S d S �N)�done� set_exceptionr �TimeoutErrorr )r r r � on_timeout@ s �z _set_timeout.<locals>.on_timeoutc s � � ��S r! )�remove_timeout)�_)�io_loop�timeout_handler r �<lambda>F s z_set_timeout.<locals>.<lambda>�r N)r �IOLoop�current�add_timeout�add_done_callback)r r r% r )r r( r) r �_set_timeout; s �r0 c @ s( e Zd Zd dd�Zdee fdd�ZdS ) �_QueueIterator�q� Queue[_T]r Nc C s || _ d S r! )r2 )�selfr2 r r r �__init__J � z_QueueIterator.__init__c C � | j �� S r! )r2 �get�r4 r r r � __anext__M r6 z_QueueIterator.__anext__)r2 r3 r N)r r r r5 r r r: r r r r r1 I s r1 c @ s� e Zd ZdZdZd1deddfdd�Zedefdd ��Zdefd d�Z de fdd �Zde fdd�Z d2de deeeejf ddfdd�Zde ddfdd�Z d2deeeejf dee fdd�Zde fdd�Zd3dd�Z d2deeeejf ded fdd�Zdee fdd �Zd3d!d"�Zde fd#d$�Zde ddfd%d&�Zde ddfd'd(�Zd3d)d*�Z de!fd+d,�Z"de!fd-d.�Z#de!fd/d0�Z$dS )4r a� Coordinate producer and consumer coroutines. If maxsize is 0 (the default) the queue size is unbounded. .. testcode:: import asyncio from tornado.ioloop import IOLoop from tornado.queues import Queue q = Queue(maxsize=2) async def consumer(): async for item in q: try: print('Doing work on %s' % item) await asyncio.sleep(0.01) finally: q.task_done() async def producer(): for item in range(5): await q.put(item) print('Put %s' % item) async def main(): # Start consumer without waiting (since it never finishes). IOLoop.current().spawn_callback(consumer) await producer() # Wait for producer to put all tasks. await q.join() # Wait for consumer to finish all tasks. print('Done') asyncio.run(main()) .. testoutput:: Put 0 Put 1 Doing work on 0 Put 2 Doing work on 1 Put 3 Doing work on 2 Put 4 Doing work on 3 Doing work on 4 Done In versions of Python without native coroutines (before 3.5), ``consumer()`` could be written as:: @gen.coroutine def consumer(): while True: item = yield q.get() try: print('Doing work on %s' % item) yield gen.sleep(0.01) finally: q.task_done() .. versionchanged:: 4.3 Added ``async for`` support in Python 3.5. Nr �maxsizer c C sb |d u rt d��|dk rtd��|| _| �� t�g �| _t�g �| _d| _t � | _ | j �� d S )Nzmaxsize can't be Noner zmaxsize can't be negative)� TypeError� ValueError�_maxsize�_init�collections�deque�_getters�_putters�_unfinished_tasksr � _finished�set)r4 r; r r r r5 � s zQueue.__init__c C s | j S )z%Number of items allowed in the queue.)r>