sdZddlmZddlmZddlmZgdZGddeZ Gd d eZ Gd d Z d S)aAn 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)EmptyFullQueueceZdZdZdS)rz4Exception raised by Queue.get(block=0)/get_nowait().N__name__ __module__ __qualname____doc__/srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/util/queue.pyrr::DrrceZdZdZdS)rz4Exception raised by Queue.put(block=0)/put_nowait().Nr rrrrr$rrrcheZdZddZdZdZdZdd Zd Zdd Z d Z d Z dZ dZ dZdZdZdS)r rFc||tj|_tj|j|_tj|j|_||_dS)zInitialize 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)_initrRLockmutex Condition not_emptynot_fulluse_lifo)selfmaxsizers r__init__zQueue.__init__+s^ 7 _&& #,TZ88"+DJ77   rc|j|}|j|S)z9Return the approximate size of the queue (not reliable!).)racquire_qsizereleaserns rqsizez Queue.qsizeBs>  KKMM rc|j|}|j|S)zKReturn True if the queue is empty, False otherwise (not reliable!).)rr"_emptyr$r%s remptyz Queue.emptyJs>  KKMM rc|j|}|j|S)zJReturn True if the queue is full, False otherwise (not reliable!).)rr"_fullr$r%s rfullz Queue.fullSs>  JJLL rTNc|j |s|rtn|B|r-|j|-n|dkrt dt |z}|rL|t z }|dkrt|j||L|||j |j dS#|j wxYw)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). Nr#'timeout' must be a positive number) rr"r,rwait ValueError_time_putrnotifyr$)ritemblocktimeoutendtime remainings rputz Queue.put\sR  $ 2::<<Jjjll)M&&(((jjll)Q;;$%JKKK''G+jjll2 '%'' 1I C''" M&&y111 jjll2 IIdOOO N ! ! # # # M ! ! # # # # #DM ! ! # # # #s DE E'c.||dS)zPut 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;rr6s r put_nowaitzQueue.put_nowaits xxe$$$rc|j |s|rtn|B|r-|j|-n|dkrt dt |z}|rL|t z }|dkrt|j||L|}|j ||j S#|j wxYw)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). Nrr/r0) rr"r)rr1r2r3_getrr5r$)rr7r8r9r:r6s rgetz Queue.getsP     % 3;;== K kkmm*N'')))kkmm*Q;;$%JKKK''G+kkmm3 '%'' 1I C''# N'' 222 kkmm3 99;;D M " " " N " " $ $ $ $DN " " $ $ $ $s DE E&c,|dS)zRemove and return an item from the queue without blocking. Only get an item if one is immediately available. Otherwise raise the ``Empty`` exception. F)rArs r get_nowaitzQueue.get_nowaitsxxrc:||_t|_dSN)rrqueue)rrs rrz Queue._inits WW rc*t|jSrF)lenrGrCs rr#z Queue._qsizes4:rc|j SrF)rGrCs rr)z Queue._emptys :~rcR|jdkot|j|jkS)Nr)rrIrGrCs rr,z Queue._fulls#|aCC OOt|$CCrc:|j|dSrF)rGappendr=s rr4z Queue._puts $rct|jr|jS|jSrF)rrGpoppopleftrCs rr@z Queue._gets4 = (:>>## #:%%'' 'r)rF)TN)r r rr r'r*r-r;r>rArDrr#r)r,r4r@rrrr r *s!!!!.!$!$!$!$F%%% % % % %DDDD   (((((rr N) r collectionsrrr3compatr__all__ Exceptionrrr rrrrUs   % $ $     I        9   g(g(g(g(g(g(g(g(g(g(r