mf dZddlZddlmZddlmZddlmZerddlmZgdZ Gdd e Z Gd d e Z Gd d e ZdS)a A fork of Python 3.6's stdlib queue with Lock swapped out for RLock to avoid a deadlock while garbage collecting. See https://codewithoutrules.com/2017/08/16/concurrency-python/ https://bugs.python.org/issue14976 https://github.com/sqlalchemy/sqlalchemy/blob/4eb747b61f0c1b1c25bdee3856d7195d10a0c227/lib/sqlalchemy/queue.py#L1 We also vendor the code to evade eventlet's broken monkeypatching, see https://github.com/getsentry/sentry-python/pull/484 N)deque)time)MYPY)Any)EmptyFullQueueceZdZdZdS)rz4Exception raised by Queue.get(block=0)/get_nowait().N__name__ __module__ __qualname____doc__H/opt/imunify360/venv/lib64/python3.11/site-packages/sentry_sdk/_queue.pyrr::DrrceZdZdZdS)rz4Exception raised by Queue.put(block=0)/put_nowait().Nr rrrrr rrrcleZdZdZddZdZdZdZdZdZ dd Z dd Z d Z dZ dZdZdZdZd S)r zjCreate a queue object with a given maximum size. If maxsize is <= 0, the queue size is infinite. rc0||_||tj|_tj|j|_tj|j|_tj|j|_d|_ dS)Nr) maxsize_init threadingRLockmutex Condition not_emptynot_fullall_tasks_doneunfinished_tasksselfrs r__init__zQueue.__init__+s}  7 _&& #,TZ88"+DJ77 (1$*== !rc|j5|jdz }|dkr.|dkrtd|j||_ddddS#1swxYwYdS)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 ValueError notify_all)r" unfinisheds r task_donezQueue.task_doneBs  / /.2JQ>>$%HIII#..000$.D !  / / / / / / / / / / / / / / / / / /sAAA"Ac|j5|jr |j|j ddddS#1swxYwYdS)aBlocks 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 waitr"s rjoinz Queue.joinXs  + +' +#((***' + + + + + + + + + + + + + + + + + + +s(=AAcl|j5|cdddS#1swxYwYdS)z9Return the approximate size of the queue (not reliable!).Nr_qsizer,s rqsizez Queue.qsizeesy Z ! !;;== ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s )--cn|j5| cdddS#1swxYwYdS)aReturn 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. Nr/r,s remptyz Queue.emptyjs~Z % %{{}}$ % % % % % % % % % % % % % % % % % %s *..c|j5d|jcxko|knccdddS#1swxYwYdS)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)rrr0r,s rfullz Queue.fullxsZ 5 5t|4444t{{}}4444 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s'<AATNc|j5|jdkr|s,||jkrtn|T||jkr6|j||jk6n|dkrt dt |z}||jkrU|t z }|dkrt|j|||jkU|||xjdz c_|j ddddS#1swxYwYdS)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). rN''timeout' must be a non-negative numberr%) rrr0rr+r&r_putr rnotify)r"itemblocktimeoutendtime remainings rputz Queue.puts] $ $|a6{{}} 44"ff 5_++--4<77 **,,,++--4<77q[[$%NOOO"ffw.G++--4<77$+dff$4 $++"&J **9555 ++--4<77 IIdOOO  ! !Q & ! ! N ! ! # # #' $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $sE'E<<FFc|j5|s#|stn|B|s-|j|-n|dkrt dt |z}|sS|t z }|dkrt|j||S|}|j|cdddS#1swxYwYdS)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). Nrr7r8) rr0rr+r&r_getrr:)r"r<r=r>r?r;s rgetz Queue.getsx^   3{{}}"''M"++--*N'')))++--*1 !JKKK&&7*++--3 '$&& 0I C''#gg N'' 222 ++--3 99;;D M " " "%                  sD%D::D>D>c0||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. Fr<)r@r"r;s r put_nowaitzQueue.put_nowaits xxEx***rc.|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. FrE)rCr,s r get_nowaitzQueue.get_nowaits xxex$$$rc,t|_dSN)rqueuer!s rrz Queue._initsWW rc*t|jSrK)lenrLr,s rr0z Queue._qsizes4:rc:|j|dSrK)rLappendrFs rr9z Queue._puts $rc4|jSrK)rLpopleftr,s rrBz Queue._getsz!!###r)r)TN)r r rrr#r)r-r1r3r5r@rCrGrIrr0r9rBrrrr r %s """".///, + + +!!! % % % 5 5 5$$$$@>+++%%%   $$$$$rr )rr collectionsrrsentry_sdk._typesrtypingr__all__ Exceptionrrobjectr rrrrYs   """""" $ $ $     I        9   ~$~$~$~$~$F~$~$~$~$~$r