U if @sdZddlZddlZddlZddlmZddlmZGdddeZGdd d eZ Gd d d Z Gd d d e Z Gddde Z dS))Queue PriorityQueue LifoQueue QueueFull QueueEmptyN)events)locksc@seZdZdZdS)rz;Raised when Queue.get_nowait() is called on an empty Queue.N__name__ __module__ __qualname____doc__rr3/opt/alt/python38/lib64/python3.8/asyncio/queues.pyr src@seZdZdZdS)rzDRaised when the Queue.put_nowait() method is called on a full Queue.Nr rrrrrsrc@seZdZdZd)ddddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ e ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(ZdS)*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. rNloopcCsp|dkrt|_n||_tjdtdd||_t|_ t|_ d|_ t j |d|_|j||dS)Nz[The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.) stacklevelrr)rZget_event_loop_loopwarningswarnDeprecationWarning_maxsize collectionsdeque_getters_putters_unfinished_tasksr ZEvent _finishedset_init)selfmaxsizerrrr__init__!s    zQueue.__init__cCst|_dSN)rr_queuer"r#rrrr!6sz Queue._initcCs |jSr%)r&popleftr"rrr_get9sz Queue._getcCs|j|dSr%r&appendr"itemrrr_put<sz Queue._putcCs&|r"|}|s|dq"qdSr%)r(ZdoneZ set_result)r"waitersZwaiterrrr _wakeup_nextAs  zQueue._wakeup_nextcCs(dt|jdt|dd|dS)N)typer id_formatr)rrr__repr__IszQueue.__repr__cCsdt|jd|dS)Nr2r3r4)r5r r7r)rrr__str__Lsz Queue.__str__cCs~d|j}t|ddr,|dt|j7}|jrH|dt|jd7}|jrd|dt|jd7}|jrz|d|j7}|S)Nzmaxsize=r&z _queue=z _getters[]z _putters[z tasks=)rgetattrlistr&rlenrr)r"resultrrrr7Os  z Queue._formatcCs t|jS)zNumber of items in the queue.)r=r&r)rrrqsize[sz 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)rrremptydsz Queue.emptycCs |jdkrdS||jkSdS)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. rFN)rr?r)rrrfullhs z Queue.fullc s|r|j}|j|z|IdHWq|z|j|Wntk r`YnX|s~|s~| |jYqXq| |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) rBr create_futurerr,cancelremove ValueError cancelledr1 put_nowait)r"r.Zputterrrrputss    z Queue.putcCs>|r t|||jd7_|j||jdS)zyPut an item into the queue without blocking. If no free slot is immediately available, raise QueueFull. rN)rBrr/rrclearr1rr-rrrrHs   zQueue.put_nowaitc s|r|j}|j|z|IdHWq|z|j|Wntk r`YnX|s~|s~| |jYqXq| S)zoRemove and return an item from the queue. If queue is empty, wait until an item is available. N) rArrCrr,rDrErFrGr1 get_nowait)r"getterrrrgets    z Queue.getcCs$|r t|}||j|S)zRemove and return an item from the queue. Return an item if one is immediately available, else raise QueueEmpty. )rArr*r1rr-rrrrKs  zQueue.get_nowaitcCs8|jdkrtd|jd8_|jdkr4|jdS)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)rrFrr r)rrr task_dones   zQueue.task_donecs|jdkr|jIdHdS)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 r r rr$r!r*r/r1r8r9r7r?propertyr#rArBrIrHrMrKrNrPrrrrrs(      rc@s4eZdZdZddZejfddZejfddZ dS) rzA subclass of Queue; retrieves entries in priority order (lowest first). Entries are typically tuples of the form: (priority number, data). cCs g|_dSr%r@r'rrrr!szPriorityQueue._initcCs||j|dSr%r@)r"r.heappushrrrr/szPriorityQueue._putcCs ||jSr%r@)r"heappoprrrr*szPriorityQueue._getN) r r r rr!heapqrRr/rSr*rrrrrsrc@s(eZdZdZddZddZddZdS) rzEA subclass of Queue that retrieves most recently added entries first.cCs g|_dSr%r@r'rrrr!szLifoQueue._initcCs|j|dSr%r+r-rrrr/szLifoQueue._putcCs |jSr%)r&popr)rrrr*szLifoQueue._getN)r r r rr!r/r*rrrrrsr) __all__rrTrrr Exceptionrrrrrrrrrs  K