\d&dZddlZddlZddlmZddlmZddlmZGddeZ Gd d eZ Gd d ej Z Gd de Z Gdde ZdS))Queue PriorityQueue LifoQueue QueueFull QueueEmptyN) GenericAlias)locks)mixinsceZdZdZdS)rz;Raised when Queue.get_nowait() is called on an empty Queue.N__name__ __module__ __qualname____doc__..\python\lib\asyncio\queues.pyrr sEEDrrceZdZdZdS)rzDRaised when the Queue.put_nowait() method is called on a full Queue.Nr rrrrrsNNDrrceZdZdZddZdZdZdZdZdZ d Z e e Z d Zd Zed Zd ZdZdZdZdZdZdZdZdS)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. rc||_tj|_tj|_d|_t j|_|j | |dS)Nr) _maxsize collectionsdeque_getters_putters_unfinished_tasksr Event _finishedset_initselfmaxsizes r__init__zQueue.__init__!sl $)++ #)++ !"  7rc6tj|_dSN)rr_queuer"s rr!z Queue._init/s!')) rc4|jSr')r(popleftr#s r_getz Queue._get2s{""$$$rc:|j|dSr'r(appendr#items r_putz Queue._put5 4     rc|rC|}|s|ddS|AdSdSr')r*done set_result)r#waiterswaiters r _wakeup_nextzQueue._wakeup_next:s` __&&F;;== !!$'''      rc~dt|jdt|dd|dS)N)typerid_formatr+s r__repr__zQueue.__repr__Bs=K4::&KKBtHHKKK$,,..KKKKrc\dt|jd|dS)Nr;r<r=)r>rr@r+s r__str__z Queue.__str__Es,:4::&::::::rc d|j}t|ddr|dt|jz }|jr|dt |jdz }|jr|dt |jdz }|jr |d|jz }|S)Nzmaxsize=r(z _queue=z _getters[]z _putters[z tasks=)rgetattrlistr(rlenrr)r#results rr@z Queue._formatJs-DM-- 44 ( ( 7 6dk!2!266 6F = 9 83t}#5#5888 8F = 9 83t}#5#5888 8F  ! 9 8 688 8F rc*t|jS)zNumber of items in the queue.)rHr(r+s rqsizez Queue.qsizeVs4;rc|jS)z%Number of items allowed in the queue.)rr+s rr$z Queue.maxsizeZs }rc|j S)z3Return True if the queue is empty, False otherwise.r(r+s remptyz Queue.empty_s ;rcV|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)rrKr+s rfullz Queue.fullcs+ =A  5::<<4=0 0rc$K|r|}|j| |d{Vn#| |j|n#t$rYnwxYw|s.|s| |jxYw|| |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) rQ _get_loop create_futurerr/cancelremove ValueError cancelledr9 put_nowait)r#r1putters rputz Queue.putns iikk ^^%%3355F M  ( ( (    M((0000!Dyy{{56+;+;+=+=5%%dm444%iikk &t$$$1A!!C&8BC& B C&B  AC&c|rt|||xjdz c_|j||jdS)zyPut an item into the queue without blocking. If no free slot is immediately available, raise QueueFull. r N)rQrr2rrclearr9rr0s rrYzQueue.put_nowaitsl 99;; O $ !#  $-(((((rc"K|r|}|j| |d{Vn#| |j|n#t$rYnwxYw|s.|s| |jxYw|| S)zoRemove and return an item from the queue. If queue is empty, wait until an item is available. N) rOrSrTrr/rUrVrWrXr9 get_nowait)r#getters rgetz Queue.gets jjll ^^%%3355F M  ( ( (    M((0000!Dzz||5F,<,<,>,>5%%dm444%jjll &   r\c|rt|}||j|S)zRemove and return an item from the queue. Return an item if one is immediately available, else raise QueueEmpty. )rOrr,r9rr0s rr`zQueue.get_nowaitsB ::<<  yy{{ $-((( rc|jdkrtd|xjdzc_|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 timesr N)rrWrr r+s r task_donezQueue.task_donese  !Q & &@AA A !#  !Q & & N    ' &rcbK|jdkr!|jd{VdSdS)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+s rjoinz Queue.joinsJ  !A % %.%%'' ' ' ' ' ' ' ' ' ' & %rN)r)rrrrr%r!r,r2r9rArC classmethodr__class_getitem__r@rKpropertyr$rOrQr[rYrbr`rerhrrrrrsR      ***%%%!!! LLL;;;$ L11      X 1 1 1%%%6 ) ) )!!!4   !!!( ( ( ( ( (rrc@eZdZdZdZejfdZejfdZ dS)rzA subclass of Queue; retrieves entries in priority order (lowest first). Entries are typically tuples of the form: (priority number, data). cg|_dSr'rNr"s rr!zPriorityQueue._init  rc(||j|dSr'rN)r#r1heappushs rr2zPriorityQueue._putsd#####rc"||jSr'rN)r#heappops rr,zPriorityQueue._getswt{###rN) rrrrr!heapqrpr2rrr,rrrrrsc #(.$$$$!=$$$$$$rrc$eZdZdZdZdZdZdS)rzEA subclass of Queue that retrieves most recently added entries first.cg|_dSr'rNr"s rr!zLifoQueue._initrnrc:|j|dSr'r.r0s rr2zLifoQueue._putr3rc4|jSr')r(popr+s rr,zLifoQueue._gets{   rN)rrrrr!r2r,rrrrrsGOO!!!!!!!!rr)__all__rrstypesrr r Exceptionrr_LoopBoundMixinrrrrrrr~s= L                 B(B(B(B(B(F "B(B(B(J $ $ $ $ $E $ $ $ ! ! ! ! ! ! ! ! ! !r