grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ fƒ"ã@sdZyddlZWnek r6ddlZYnXddlmZddlmZmZyddl m Z Wn"ek r•ddl m Z YnXddd d d gZ Gd d„de ƒZ Gd d„de ƒZGdd „d ƒZGdd „d eƒZGdd „d eƒZdS)z'A multi-producer, multi-consumer queue.éN)Údeque)ÚheappushÚheappop)Ú monotonic)ÚtimeÚEmptyÚFullÚQueueÚ PriorityQueueÚ LifoQueuec@seZdZdZdS)rz4Exception raised by Queue.get(block=0)/get_nowait().N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú*/opt/alt/python34/lib64/python3.4/queue.pyrs c@seZdZdZdS)rz4Exception raised by Queue.put(block=0)/put_nowait().N)r r rrrrrrrs c@sÍeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dddd„Z dddd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd „ZdS)!r zjCreate a queue object with a given maximum size. If maxsize is <= 0, the queue size is infinite. rcCsq||_|j|ƒtjƒ|_tj|jƒ|_tj|jƒ|_tj|jƒ|_d|_ dS)Nr) ÚmaxsizeÚ_initÚ threadingZLockÚmutexZ ConditionÚ not_emptyÚnot_fullÚall_tasks_doneÚunfinished_tasks)ÚselfrrrrÚ__init__s  zQueue.__init__c Csa|j�R|jd}|dkrN|dkr>tdƒ‚n|jjƒn||_WdQXdS)a.Indicate that a formerly enqueued task is complete. Used by Queue consumer threads. 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 a ValueError if called more times than there were items placed in the queue. érz!task_done() called too many timesN)rrÚ ValueErrorZ notify_all)rZ unfinishedrrrÚ task_done5s    zQueue.task_donecCs1|j�"x|jr&|jjƒq WWdQXdS)aƒBlocks 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 thread calls task_done() to indicate the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks. N)rrÚwait)rrrrÚjoinKs  z Queue.joincCs|j�|jƒSWdQXdS)z9Return the approximate size of the queue (not reliable!).N)rÚ_qsize)rrrrÚqsizeXs z Queue.qsizecCs|j�|jƒ SWdQXdS)aÝReturn True if the queue is empty, False otherwise (not reliable!). This method is likely to be removed at some point. Use qsize() == 0 as a direct substitute, but be aware that either approach risks a race condition where a queue can grow before the result of empty() or qsize() can be used. To create code that needs to wait for all queued tasks to be completed, the preferred technique is to use the join() method. N)rr!)rrrrÚempty]s z Queue.emptyc Cs5|j�&d|jko(|jƒkSSWdQXdS)aOReturn True if the queue is full, False otherwise (not reliable!). This method is likely to be removed at some point. Use qsize() >= n as a direct substitute, but be aware that either approach risks a race condition where a queue can shrink before the result of full() or qsize() can be used. rN)rrr!)rrrrÚfullks z Queue.fullTNc Cs$|j�|jdkrñ|s@|jƒ|jkrît‚qîqñ|dkrxxŸ|jƒ|jkrt|jjƒqOWqñ|dkr“tdƒ‚qñtƒ|}xN|jƒ|jkrí|tƒ}|dkrÚt‚n|jj|ƒq£Wn|j|ƒ|jd7_|j j ƒWdQXdS)aPut an item into the queue. If optional args 'block' is true and 'timeout' is None (the default), block if necessary until a free slot is available. If 'timeout' is a non-negative number, it blocks at most 'timeout' seconds and raises the Full exception if no free slot was available within that time. Otherwise ('block' is false), put an item on the queue if a free slot is immediately available, else raise the Full exception ('timeout' is ignored in that case). rNz''timeout' must be a non-negative numbergr) rrr!rrrrÚ_putrrÚnotify)rÚitemÚblockÚtimeoutÚendtimeÚ remainingrrrÚputvs&         z Queue.putc Csë|j�Ü|s(|jƒsÄt‚qÄnœ|dkrWx�|jƒsS|jjƒq7Wnm|dkrrtdƒ‚nRtƒ|}xB|jƒsÃ|tƒ}|dkr°t‚n|jj|ƒq‚W|jƒ}|jjƒ|SWdQXdS)aRemove and return an item from the queue. If optional args 'block' is true and 'timeout' is None (the default), block if necessary until an item is available. If 'timeout' is a non-negative number, it blocks at most 'timeout' seconds and raises the Empty exception if no item was available within that time. Otherwise ('block' is false), return an item if one is immediately available, else raise the Empty exception ('timeout' is ignored in that case). Nrz''timeout' must be a non-negative numberg) rr!rrrrÚ_getrr&)rr(r)r*r+r'rrrÚget–s$           z Queue.getcCs|j|ddƒS)z©Put an item into the queue without blocking. Only enqueue the item if a free slot is immediately available. Otherwise raise the Full exception. r(F)r,)rr'rrrÚ put_nowaitµszQueue.put_nowaitcCs|jddƒS)z«Remove and return an item from the queue without blocking. Only get an item if one is immediately available. Otherwise raise the Empty exception. r(F)r.)rrrrÚ get_nowait½szQueue.get_nowaitcCstƒ|_dS)N)rÚqueue)rrrrrrÊsz Queue._initcCs t|jƒS)N)Úlenr1)rrrrr!Ísz Queue._qsizecCs|jj|ƒdS)N)r1Úappend)rr'rrrr%Ñsz Queue._putcCs |jjƒS)N)r1Úpopleft)rrrrr-Õsz Queue._get)r r rrrrr r"r#r$r,r.r/r0rr!r%r-rrrrr s          c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) r zœVariant of Queue that retrieves open entries in priority order (lowest first). Entries are typically tuples of the form: (priority number, data). cCs g|_dS)N)r1)rrrrrrßszPriorityQueue._initcCs t|jƒS)N)r2r1)rrrrr!âszPriorityQueue._qsizecCst|j|ƒdS)N)rr1)rr'rrrr%åszPriorityQueue._putcCs t|jƒS)N)rr1)rrrrr-èszPriorityQueue._getN)r r rrrr!r%r-rrrrr Ùs    c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) r zBVariant of Queue that retrieves most recently added entries first.cCs g|_dS)N)r1)rrrrrrïszLifoQueue._initcCs t|jƒS)N)r2r1)rrrrr!òszLifoQueue._qsizecCs|jj|ƒdS)N)r1r3)rr'rrrr%õszLifoQueue._putcCs |jjƒS)N)r1Úpop)rrrrr-øszLifoQueue._getN)r r rrrr!r%r-rrrrr ìs    )rrÚ ImportErrorZdummy_threadingÚ collectionsrÚheapqrrrrÚ__all__Ú Exceptionrrr r r rrrrÚs   Á