o ?Ogb@sdZddlZddlZddlmZddlmZddlmZGdddeZ Gd d d eZ Gd d d ej Z Gd dde Z Gddde ZdS))Queue PriorityQueue LifoQueue QueueFull QueueEmptyN) GenericAlias)locks)mixinsc@eZdZdZdS)rz;Raised when Queue.get_nowait() is called on an empty Queue.N__name__ __module__ __qualname____doc__rr5/opt/alt/python310/lib64/python3.10/asyncio/queues.pyr rc@r )rzDRaised when the Queue.put_nowait() method is called on a full Queue.Nr rrrrrrrcseZdZdZd(ejdfdd ZddZdd Zd d Z d d Z ddZ ddZ e eZddZddZeddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZZS))raA queue, useful for coordinating producer and consumer coroutines. If maxsize is less than or equal to zero, the queue size is infinite. If it is an integer greater than 0, then "await put()" will block when the queue reaches maxsize, until an item is removed by get(). Unlike the standard library Queue, you can reliably know this Queue's size with qsize(), since your single-threaded asyncio application won't be interrupted between calling qsize() and doing an operation on the Queue. rloopcsPtj|d||_t|_t|_d|_t |_ |j | |dS)Nrr) super__init___maxsize collectionsdeque_getters_putters_unfinished_tasksr ZEvent _finishedset_init)selfmaxsizer __class__rrr!s    zQueue.__init__cCst|_dSN)rr_queuer!r"rrrr 0sz Queue._initcC |jSr%)r&popleftr!rrr_get3 z Queue._getcC|j|dSr%r&appendr!itemrrr_put6z Queue._putcCs.|r|}|s|ddS|sdSdSr%)r)ZdoneZ set_result)r!waitersZwaiterrrr _wakeup_next;s   zQueue._wakeup_nextcCs(dt|jdt|dd|dS)N)typer id_formatr*rrr__repr__Cs(zQueue.__repr__cCsdt|jd|dS)Nr6r7r8)r9r r;r*rrr__str__Fsz Queue.__str__cCs~d|j}t|ddr|dt|j7}|jr$|dt|jd7}|jr2|dt|jd7}|jr=|d|j7}|S)Nzmaxsize=r&z _queue=z _getters[]z _putters[z tasks=)rgetattrlistr&rlenrr)r!resultrrrr;Ks  z Queue._formatcCs t|jS)zNumber of items in the queue.)rAr&r*rrrqsizeWs z Queue.qsizecCs|jS)z%Number of items allowed in the queue.)rr*rrrr"[sz Queue.maxsizecCs|j S)z3Return True if the queue is empty, False otherwise.r&r*rrrempty`sz Queue.emptycCs|jdkrdS||jkS)zReturn True if there are maxsize items in the queue. Note: if the Queue was initialized with maxsize=0 (the default), then full() is never True. rF)rrCr*rrrfullds z Queue.fullc s|rE|}|j|z|IdHWn(|z|j|Wn ty1Ynw|s@|s@| |j|s| |S)zPut an item into the queue. Put an item into the queue. If the queue is full, wait until a free slot is available before adding item. N) rF _get_loop create_futurerr/cancelremove ValueError cancelledr5 put_nowait)r!r1Zputterrrrputos$     z Queue.putcCs>|rt|||jd7_|j||jdS)zyPut an item into the queue without blocking. If no free slot is immediately available, raise QueueFull. rN)rFrr2rrclearr5rr0rrrrMs   zQueue.put_nowaitc s|rE|}|j|z|IdHWn(|z|j|Wn ty1Ynw|s@|s@| |j|s| S)zoRemove and return an item from the queue. If queue is empty, wait until an item is available. N) rErGrHrr/rIrJrKrLr5 get_nowait)r!getterrrrgets$    z Queue.getcCs$|rt|}||j|S)zRemove and return an item from the queue. Return an item if one is immediately available, else raise QueueEmpty. )rErr+r5rr0rrrrPs  zQueue.get_nowaitcCs<|jdkr td|jd8_|jdkr|jdSdS)a$Indicate that a formerly enqueued task is complete. Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete. If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue). Raises ValueError if called more times than there were items placed in the queue. rz!task_done() called too many timesrN)rrKrrr*rrr task_dones  zQueue.task_donecs$|jdkr|jIdHdSdS)aBlock until all items in the queue have been gotten and processed. The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks. rN)rrwaitr*rrrjoins z Queue.join)r)r rrrr Z_markerrr r+r2r5r<r= classmethodr__class_getitem__r;rCpropertyr"rErFrNrMrRrPrSrU __classcell__rrr#rrs,      rc@s4eZdZdZddZejfddZejfddZ dS) rzA subclass of Queue; retrieves entries in priority order (lowest first). Entries are typically tuples of the form: (priority number, data). cC g|_dSr%rDr'rrrr r,zPriorityQueue._initcCs||j|dSr%rD)r!r1heappushrrrr2r3zPriorityQueue._putcCs ||jSr%rD)r!heappoprrrr+r,zPriorityQueue._getN) r rrrr heapqr[r2r\r+rrrrrs rc@s(eZdZdZddZddZddZdS) rzEA subclass of Queue that retrieves most recently added entries first.cCrZr%rDr'rrrr r,zLifoQueue._initcCr-r%r.r0rrrr2r3zLifoQueue._putcCr(r%)r&popr*rrrr+r,zLifoQueue._getN)r rrrr r2r+rrrrrs  r)__all__rr]typesrr r ExceptionrrZ_LoopBoundMixinrrrrrrrs   G