B ÃÌ4]«ã@sddZddlmZddlmZddlmZdddgZGd d„deƒZ Gd d„deƒZ Gd d„dƒZ d S) aðAn adaptation of Py2.3/2.4's Queue module which supports reentrant behavior, using RLock instead of Lock for its mutex object. The Queue object is used exclusively by the sqlalchemy.pool.QueuePool class. This is to support the connection pool's usage of weakref callbacks to return connections to the underlying Queue, which can in extremely rare cases be invoked within the ``get()`` method of the Queue itself, producing a ``put()`` inside the ``get()`` and therefore a reentrant condition. é)Údeque)Útimeé)Ú threadingÚEmptyÚFullÚQueuec@seZdZdZdS)rz4Exception raised by Queue.get(block=0)/get_nowait().N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r úH/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/util/queue.pyrsc@seZdZdZdS)rz4Exception raised by Queue.put(block=0)/put_nowait().N)r r r r r r r rr$sc@s‚eZdZd!dd„Zdd„Zdd„Zd d „Zd"d d„Zdd„Zd#dd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd „Zd S)$rrFcCs:| |¡t ¡|_t |j¡|_t |j¡|_||_dS)z½Initialize a queue object with a given maximum size. If `maxsize` is <= 0, the queue size is infinite. If `use_lifo` is True, this Queue acts like a Stack (LIFO). N)Ú_initrÚRLockÚmutexZ ConditionÚ not_emptyÚnot_fullÚuse_lifo)ÚselfÚmaxsizerr r rÚ__init__+s   zQueue.__init__cCs |j ¡| ¡}|j ¡|S)z9Return the approximate size of the queue (not reliable!).)rÚacquireÚ_qsizeÚrelease)rÚnr r rÚqsizeBs  z Queue.qsizecCs |j ¡| ¡}|j ¡|S)zKReturn True if the queue is empty, False otherwise (not reliable!).)rrÚ_emptyr)rrr r rÚemptyJs  z Queue.emptycCs |j ¡| ¡}|j ¡|S)zJReturn True if the queue is full, False otherwise (not reliable!).)rrÚ_fullr)rrr r rÚfullSs  z Queue.fullTNcCs²|j ¡z–|s| ¡rŠt‚nl|dkr@xb| ¡r<|j ¡q(WnJ|dkrPtdƒ‚tƒ|}x.| ¡rˆ|tƒ}|dkrzt‚|j |¡q\W| |¡|j  ¡Wd|j  ¡XdS)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 positive 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). Nrz#'timeout' must be a positive numberg) rrrrÚwaitÚ ValueErrorÚ_timeÚ_putrÚnotifyr)rÚitemÚblockÚtimeoutÚendtimeÚ remainingr r rÚput\s&      z Queue.putcCs | |d¡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. F)r+)rr&r r rÚ put_nowaitszQueue.put_nowaitcCs°|j ¡z”|s| ¡rŠt‚nl|dkr@xb| ¡r<|j ¡q(WnJ|dkrPtdƒ‚tƒ|}x.| ¡rˆ|tƒ}|dkrzt‚|j |¡q\W| ¡}|j  ¡|S|j  ¡XdS)a Remove 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 positive 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 positive numberg) rrrrr!r"r#Ú_getrr%r)rr'r(r)r*r&r r rÚget‡s(      z Queue.getcCs | d¡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. F)r.)rr r rÚ get_nowait©szQueue.get_nowaitcCs||_tƒ|_dS)N)rrÚqueue)rrr r rr·sz Queue._initcCs t|jƒS)N)Úlenr0)rr r rr»sz Queue._qsizecCs|j S)N)r0)rr r rr¿sz Queue._emptycCs|jdkot|jƒ|jkS)Nr)rr1r0)rr r rrÃsz Queue._fullcCs|j |¡dS)N)r0Úappend)rr&r r rr$Çsz Queue._putcCs|jr|j ¡S|j ¡SdS)N)rr0ÚpopÚpopleft)rr r rr-Ës z Queue._get)rF)TN)TN)r r r rrrr r+r,r.r/rrrrr$r-r r r rr*s   # "N) r Ú collectionsrrr#ÚcompatrÚ__all__Ú Exceptionrrrr r r rÚs