Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
queues.cpython-313.pyc211 linesDownload Raw Back to __pycache__
1�

2��j�2���SrSSKrSSKrSSKrSSKJrJr SSKJrJ	r	 SSK3Jr SSKJ
r
JrJrJrJr SSKr\R$(a4SSKJrJrJr \"S5r/S	Qr"S5S\5r"SS
\5rS\S\
S\\R84SS4Sjr"SS\\5r"SS\\5r"SS\5r "SS\5r!g)a�Asynchronous queues for coroutines. These classes are very similar6to those provided in the standard library's `asyncio package7<https://docs.python.org/3/library/asyncio-queue.html>`_.8 9.. warning::10 11   Unlike the standard library's `queue` module, the classes defined here12   are *not* thread-safe. To use these queues from another thread,13   use `.IOLoop.add_callback` to transfer control to the `.IOLoop` thread14   before calling any queue methods.15 16�N)�gen�ioloop)�Future�"future_set_result_unless_cancelled)�Event)�Union�TypeVar�Generic�	Awaitable�Optional)�Deque�Tuple�Any�_T)�Queue�
PriorityQueue�	LifoQueue�	QueueFull�17QueueEmptyc��\rSrSrSrSrg)r�/z:Raised by `.Queue.get_nowait` when the queue has no items.�N��__name__�18__module__�__qualname__�__firstlineno__�__doc__�__static_attributes__r��TD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/queues.pyrr/s��D�r rc��\rSrSrSrSrg)r�5zBRaised by `.Queue.put_nowait` when a queue is at its maximum size.rNrrr r!rr5s��L�r r�future�timeout�returnc�^^^�U(aNSU4Sjjn[RR5mTRX5mTR	UU4Sj5 gg)Nc�z>�TR5(d%TR[R"55 gg�N)�done�
set_exceptionr�TimeoutError)r$s�r!�19on_timeout� _set_timeout.<locals>.on_timeout@s*����;�;�=�=��$�$�S�%5�%5�%7�8�!r c�&>�TRT5$r))�remove_timeout)�_�io_loop�timeout_handles ��r!�<lambda>�_set_timeout.<locals>.<lambda>Fs���7�+A�+A�.�+Qr �r&N)r�IOLoop�current�add_timeout�add_done_callback)r$r%r-r2r3s`  @@r!�_set_timeoutr;;sE����	9��-�-�'�'�)�� �,�,�W�A��� � �!Q�R�r c�2�\rSrSrSSjrS\\4SjrSrg)�_QueueIterator�Ir&Nc��Xlgr)��q)�selfrAs  r!�__init__�_QueueIterator.__init__Js���r c�6�URR5$r))rA�get�rBs r!�	__anext__�_QueueIterator.__anext__Ms���v�v�z�z�|�r r@)rAz	Queue[_T]r&N)	rrrrrCrrrHrrr r!r=r=Is����9�R�=�r r=c���\rSrSrSrSrSS\SS4Sjjr\S\4Sj5r	S\4Sjr20S\4S	jrS\4S21jr
SS\S\\\\R&4SS
4SjjrS\SS4SjrSS\\\\R&4S\\4SjjrS\4SjrS SjrSS\\\\R&4S\S4SjjrS\\4SjrS SjrS\4SjrS\SS4SjrS\SS4Sjr S Sjr!S\"4Sjr#S\"4Sjr$S\"4Sjr%Sr&g)!r�Qa�Coordinate producer and consumer coroutines.22 23If maxsize is 0 (the default) the queue size is unbounded.24 25.. testcode::26 27    import asyncio28    from tornado.ioloop import IOLoop29    from tornado.queues import Queue30 31    q = Queue(maxsize=2)32 33    async def consumer():34        async for item in q:35            try:36                print('Doing work on %s' % item)37                await asyncio.sleep(0.01)38            finally:39                q.task_done()40 41    async def producer():42        for item in range(5):43            await q.put(item)44            print('Put %s' % item)45 46    async def main():47        # Start consumer without waiting (since it never finishes).48        IOLoop.current().spawn_callback(consumer)49        await producer()     # Wait for producer to put all tasks.50        await q.join()       # Wait for consumer to finish all tasks.51        print('Done')52 53    asyncio.run(main())54 55.. testoutput::56 57    Put 058    Put 159    Doing work on 060    Put 261    Doing work on 162    Put 363    Doing work on 264    Put 465    Doing work on 366    Doing work on 467    Done68 69 70In versions of Python without native coroutines (before 3.5),71``consumer()`` could be written as::72 73    @gen.coroutine74    def consumer():75        while True:76            item = yield q.get()77            try:78                print('Doing work on %s' % item)79                yield gen.sleep(0.01)80            finally:81                q.task_done()82 83.. versionchanged:: 4.384   Added ``async for`` support in Python 3.5.85 86N�maxsizer&c�:�Uc[S5eUS:a[S5eXlUR5 [R87"/5Ul[R88"/5UlSUl[5Ul89URR5 g)Nzmaxsize can't be Nonerzmaxsize can't be negative)�	TypeError�90ValueError�_maxsize�_init�collections�deque�_getters�_putters�_unfinished_tasksr�	_finished�set)rBrLs  r!rC�Queue.__init__�sy���?��3�4�4��Q�;��8�9�9��
��91�92��#�)�)�"�-��
�#�)�)�"�-��
�!"������������r c��UR$)z%Number of items allowed in the queue.)rPrGs r!rL�
Queue.maxsize�s���}�}�r c�,�[UR5$)zNumber of items in the queue.)�len�_queuerGs r!�qsize�Queue.qsize�s���4�;�;��r c�$�UR(+$r)�r^rGs r!�empty�Queue.empty�s���;�;��r c�^�URS:XagUR5UR:�$)NrF)rLr_rGs r!�full�93Queue.full�s&���<�<�1����:�:�<�4�<�<�/�/r �itemr%zFuture[None]c���[5nURU5 URS5 U$![a+ URRX45 [
X25 U$f=f)aTPut an item into the queue, perhaps waiting until there is room.94 95Returns a Future, which raises `tornado.util.TimeoutError` after a96timeout.97 98``timeout`` may be a number denoting a time (on the same99scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a100`datetime.timedelta` object for a deadline relative to the101current time.102N)r�103put_nowait�104set_resultrrU�appendr;)rBrhr%r$s    r!�put�	Queue.put�se�����	$��O�O�D�!�105
���d�#��
���	*��M�M� � �$��0���)��
�	*�s�0�1A%�$A%c�`�UR5 UR(aaUR5(dS5eURR5nUR	U5 [X R
55 gUR5(a[eUR	U5 g)zkPut an item into the queue without blocking.106 107If no free slot is immediately available, raise `QueueFull`.108z)queue non-empty, why are getters waiting?N)	�_consume_expiredrTrc�popleft�_Queue__put_internalr�_getrfr)rBrh�getters   r!rj�Queue.put_nowait�sy��109	
�����=�=��:�:�<�<�L�!L�L�<��]�]�*�*�,�F�����%�.�v�y�y�{�C�
�Y�Y�[�[��O�����%r c���[5nURUR55 U$![a* URRU5 [
X!5 U$f=f)a�Remove and return an item from the queue.110 111Returns an awaitable which resolves once an item is available, or raises112`tornado.util.TimeoutError` after a timeout.113 114``timeout`` may be a number denoting a time (on the same115scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a116`datetime.timedelta` object for a deadline relative to the117current time.118 119.. note::120 121   The ``timeout`` argument of this method differs from that122   of the standard library's `queue.Queue.get`. That method123   interprets numeric values as relative timeouts; this one124   interprets them as absolute deadlines and requires125   ``timedelta`` objects for relative timeouts (consistent126   with other timeouts in Tornado).127 128)rrk�129get_nowaitrrTrlr;)rBr%r$s   r!rF�	Queue.get�s\��.���	*����d�o�o�/�0��
���	*��M�M� � ��(���)��
�	*�s�-�0A!� A!c�d�UR5 UR(aeUR5(dS5eURR5upUR	U5 [US5 UR
5$UR5(aUR
5$[e)z�Remove and return an item from the queue without blocking.130 131Return an item if one is immediately available, else raise132`QueueEmpty`.133z(queue not full, why are putters waiting?N)	rprUrfrqrrrrsr_r)rBrh�putters   r!rw�Queue.get_nowaits���	
�����=�=��9�9�;�;�J� J�J�;��=�=�0�0�2�L�D�����%�.�v�t�<��9�9�;��
�Z�Z�\�\��9�9�;���r c��URS::a[S5eU=RS-slURS:XaURR5 gg)a�Indicate that a formerly enqueued task is complete.134 135Used by queue consumers. For each `.get` used to fetch a task, a136subsequent call to `.task_done` tells the queue that the processing137on the task is complete.138 139If a `.join` is blocking, it resumes when all items have been140processed; that is, when every `.put` is matched by a `.task_done`.141 142Raises `ValueError` if called more times than `.put`.143rz!task_done() called too many times�N)rVrOrWrXrGs r!�	task_done�Queue.task_donesR���!�!�Q�&��@�A�A����!�#���!�!�Q�&��N�N��� �'r c�8�URRU5$)z�Block until all items in the queue are processed.144 145Returns an awaitable, which raises `tornado.util.TimeoutError` after a146timeout.147)rW�wait)rBr%s  r!�join�148Queue.join$s���~�~�"�"�7�+�+r c��[U5$r))r=rGs r!�	__aiter__�Queue.__aiter__.s
���d�#�#r c�8�[R"5Ulgr))rRrSr^rGs r!rQ�Queue._init2s��!�'�'�)��r c�6�URR5$r))r^rqrGs r!rs�149Queue._get5s���{�{�"�"�$�$r c�:�URRU5 gr)�r^rl�rBrhs  r!�_put�150Queue._put8��������4� r c��U=RS-
slURR5 URU5 g)Nr})rVrW�clearr�r�s  r!�__put_internal�Queue.__put_internal=s.�����!�#���������	�	�$�r c��UR(awURSSR5(aRURR5 UR(a'URSSR5(aMRUR(atURSR5(aQURR5 UR(a%URSR5(aMOgggg)Nrr})rUr*rqrTrGs r!rp�Queue._consume_expiredBs����m�m��
�
�a� 0�� 3� 8� 8� :� :��M�M�!�!�#��m�m��
�
�a� 0�� 3� 8� 8� :� :��m�m��
�
�a� 0� 5� 5� 7� 7��M�M�!�!�#��m�m��
�
�a� 0� 5� 5� 7� 7�m� 7�mr c��S[U5RS[[U55SUR	5S3$)N�<z at � �>)�typer�hex�id�_formatrGs r!�__repr__�Queue.__repr__Js7���4��:�&�&�'�t�C��4��M�?�!�D�L�L�N�;K�1�M�Mr c�V�S[U5RSUR5S3$)Nr�r�r�)r�rr�rGs r!�__str__�
Queue.__str__Ms)���4��:�&�&�'�q�����(8��:�:r c�d�SUR<3n[USS5(aUSUR--
nUR(aUS[	UR5--
nUR151(aUS[	UR1525--
nUR(aUSUR--
nU$)Nzmaxsize=r^z	 queue=%rz getters[%s]z putters[%s]z	 tasks=%s)rL�getattrr^rTr]rUrV)rB�results  r!r��
Queue._formatPs����D�L�L�+�,���4��4�(�(��k�D�K�K�/�/�F��=�=��n�s�4�=�=�'9�9�9�F��=�=��n�s�4�=�=�'9�9�9�F��!�!��k�D�$:�$:�:�:�F��
r )rWrTrPrUr^rV)rr)r6)'rrrrrr^�intrC�propertyrLr_�boolrcrfrrr�float�datetime�	timedeltarmrjrrFrwr~r�r=r�rQrsr�rrrp�strr�r�r�rrr r!rrQs���A�J�F�
��
�D�
������� �s� ��t��0�d�0�OS����!)�%��x�7I�7I�0I�*J�!K��	��.&�r�&�d�&�"EI����e�X�-?�-?�&?� @�A��	�2���>�B��$!�&EI�,���e�X�-?�-?�&?� @�A�,�	�4��,�$�>�"�-�$�*�%�b�%�!��!��!�153�2��$��154$�N�#�N�;��;�155��156r rc�B�\rSrSrSrS157SjrS\SS4SjrS\4SjrS	r	g)ri]abA `.Queue` that retrieves entries in priority order, lowest first.158 159Entries are typically tuples like ``(priority number, data)``.160 161.. testcode::162 163    import asyncio164    from tornado.queues import PriorityQueue165 166    async def main():167        q = PriorityQueue()168        q.put((1, 'medium-priority item'))169        q.put((0, 'high-priority item'))170        q.put((10, 'low-priority item'))171 172        print(await q.get())173        print(await q.get())174        print(await q.get())175 176    asyncio.run(main())177 178.. testoutput::179 180    (0, 'high-priority item')181    (1, 'medium-priority item')182    (10, 'low-priority item')183r&Nc��/Ulgr)rbrGs r!rQ�PriorityQueue._initz�	����r rhc�F�[R"URU5 gr))�heapq�heappushr^r�s  r!r��PriorityQueue._put}s��
���t�{�{�D�)r c�B�[R"UR5$r))r��heappopr^rGs r!rs�PriorityQueue._get�s���}�}�T�[�[�)�)r rbr6�184rrrrrrQrr�rsrrr r!rr]s+���8�*��*��*�*�b�*r rc�B�\rSrSrSrS185SjrS\SS4SjrS\4SjrS	r	g)ri�a�A `.Queue` that retrieves the most recently put items first.186 187.. testcode::188 189    import asyncio190    from tornado.queues import LifoQueue191 192    async def main():193        q = LifoQueue()194        q.put(3)195        q.put(2)196        q.put(1)197 198        print(await q.get())199        print(await q.get())200        print(await q.get())201 202    asyncio.run(main())203 204.. testoutput::205 206    1207    2208    3209r&Nc��/Ulgr)rbrGs r!rQ�LifoQueue._init�r�r rhc�:�URRU5 gr)r�r�s  r!r��LifoQueue._put�r�r c�6�URR5$r))r^�poprGs r!rs�LifoQueue._get�s���{�{��� � r rbr6r�rr r!rr�s+���4�!��!��!�!�b�!r r)"rrRr�r��tornadorr�tornado.concurrentrr�
tornado.locksr�typingrr	r210rr�
TYPE_CHECKINGr
rrr�__all__�	Exceptionrrr�r�r;r=rrrrr r!�<module>r�s��������I��?�?�
�	���(�(��T�]��211L��	��	�	�	�	�S��S�"�4���0B�0B�#B�C�S�	�S��W�R�[��I�G�B�K�I�X$*�E�$*�N"!��"!r 
codekingpro/portable-devtools · Team Ai