
    F\h%                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJrJr  / SQr " S S	\	\R                  5      r " S
 S\	\R                   5      r " S S\	\R$                  5      rSrSr\R*                  R-                  S\5      rS rS rSS\S.S jjrS r\R:                  " 5       r " S S5      r\R@                  " \\\5        g)z+Cross-interpreter Queues High Level Module.    N   )_crossinterp)
QueueErrorQueueNotFoundError)UNBOUND_ERRORUNBOUND_REMOVE)UNBOUNDr   r   createlist_allQueuer   r   
QueueEmpty	QueueFullItemInterpreterDestroyedc                       \ rS rSrSrSrg)r      zaRaised from get_nowait() when the queue is empty.

It is also raised from get() if it times out.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       7/usr/lib/python3.13/test/support/interpreters/queues.pyr   r          r   r   c                       \ rS rSrSrSrg)r   "   z`Raised from put_nowait() when the queue is full.

It is also raised from put() if it times out.
r   Nr   r   r   r   r   r   "   r   r   r   c                       \ rS rSrSrSrg)r   )   z#Raised from get() and get_nowait().r   Nr   r   r   r   r   r   )   s    -r   r   queuec                 `    U [         L a  [        R                   n [        R                  " U 5      $ N)r	   r   serialize_unbound)unbounds    r   _serialize_unboundr&   5   s&    '&&))'22r   c                 n    [         R                  " U [        5      nU[         R                  L a  [        nU$ r#   )r   resolve_unboundr   r	   )flagresolveds     r   _resolve_unboundr+   ;   s-    ++D2JKH<'''Or   F)syncobjunbounditemsc                    U(       a  [         O[        n[        U5      nUu  n[        R                  " XU5      n[        XcUS9$ )a=  Return a new cross-interpreter queue.

The queue may be used to pass data safely between interpreters.

"syncobj" sets the default for Queue.put()
and Queue.put_nowait().

"unbounditems" likewise sets the default.  See Queue.put() for
supported values.  The default value is UNBOUND, which replaces
the unbound item.
_fmt_unbound)_SHARED_ONLY_PICKLEDr&   _queuesr
   r   )maxsizer,   r-   fmtr%   	unboundopqids          r   r
   r
   B   s;     ",xC .GJI
..y
1C11r   c                  |    [         R                  " 5        V VVs/ s H  u  pn[        XU4S9PM     snnn $ s  snnn f )z!Return a list of all open queues.r/   )r4   r   r   )r8   r6   r7   s      r   r   r   U   s@     (/'7'7'9;'9#) #9,7'9; ; ;s   7c                      ^  \ rS rSrSrSSS.U 4S jjrS rS rS rS	 r	S
 r
\S 5       r\S 5       rS rS rS rSSSSS.S jjrSSS.S jrSSS.S jjrS rSrU =r$ )r   ]   zA cross-interpreter queue.Nr/   c                 > [        U[        5      (       a  [        U5      nO[        SU< 35      eUc8  Uc  [        R                  " U5      u  p$U4nO7[        R                  " U5      u  p%OUc  [        R                  " U5      u  pTU4n [
        U   nU$ ! [         aD    [        TU ]!  U 5      nXl	        X&l
        X6l        U[
        U'   [        R                  " U5         U$ f = f)Nzid must be an int, got )
isinstanceint	TypeErrorr4   get_queue_defaults_known_queuesKeyErrorsuper__new___idr0   r1   bind)clsidr0   r1   op_self	__class__s          r   rD   Queue.__new__`   s    b#RB5bV<==<"55b95!44R8a..r2EAuH	 $D   	7?3'DHI$M $M"LL	s   	B A
C%$C%c                      [         R                  " U R                  5         [        U R                  	 g ! [         a     Nf = f! [
         a     g f = fr#   )r4   releaserE   r   rA   rB   rK   s    r   __del__Queue.__del__z   sO    	OODHH%	dhh' " 		  		s     5 A 
AA
AAc                 L    [        U 5      R                   SU R                   S3$ )N())typer   rH   rP   s    r   __repr__Queue.__repr__   s$    t*%%&ay22r   c                 ,    [        U R                  5      $ r#   )hashrE   rP   s    r   __hash__Queue.__hash__   s    DHH~r   c                     U R                   4$ r#   rE   rP   s    r   __getnewargs__Queue.__getnewargs__   s    {r   c                     g r#   r   rP   s    r   __getstate__Queue.__getstate__   s    r   c                     U R                   $ r#   r^   rP   s    r   rH   Queue.id   s    xxr   c                      U R                   $ ! [         a4    [        R                  " U R                  5      U l         U R                   s $ f = fr#   )_maxsizeAttributeErrorr4   get_maxsizerE   rP   s    r   r5   Queue.maxsize   s@    	!==  	!#//9DM== 	!s    ;AAc                 (    U R                  5       S:H  $ )Nr   )qsizerP   s    r   emptyQueue.empty   s    zz|q  r   c                 B    [         R                  " U R                  5      $ r#   )r4   is_fullrE   rP   s    r   full
Queue.full   s    txx((r   c                 B    [         R                  " U R                  5      $ r#   )r4   	get_countrE   rP   s    r   rl   Queue.qsize   s      **r   g{Gz?)r,   r%   _delayc                   Uc  U R                   nOU(       a  [        O[        nUc  U R                  u  nO[	        U5      u  nUb4  [        U5      nUS:  a  [        S5      e[        R                  " 5       U-   nU[        L a  [        R                  " U5      n  [        R                  " U R                  XU5        g! [         a=  n	Ub  [        R                  " 5       W:  a  e [        R                  " U5         Sn	A	OSn	A	ff = fMp  )ag  Add the object to the queue.

This blocks while the queue is full.

If "syncobj" is None (the default) then it uses the
queue's default, set with create_queue().

If "syncobj" is false then all objects are supported,
at the expense of worse performance.

If "syncobj" is true then the object must be "shareable".
Examples of "shareable" objects include the builtin singletons,
str, and memoryview.  One benefit is that such objects are
passed through the queue efficiently.

The key difference, though, is conceptual: the corresponding
object returned from Queue.get() will be strictly equivalent
to the given obj.  In other words, the two objects will be
effectively indistinguishable from each other, even if the
object is mutable.  The received object may actually be the
same object, or a copy (immutable values only), or a proxy.
Regardless, the received object should be treated as though
the original has been shared directly, whether or not it
actually is.  That's a slightly different and stronger promise
than just (initial) equality, which is all "syncobj=False"
can promise.

"unbound" controls the behavior of Queue.get() for the given
object if the current interpreter (calling put()) is later
destroyed.

If "unbound" is None (the default) then it uses the
queue's default, set with create_queue(),
which is usually UNBOUND.

If "unbound" is UNBOUND_ERROR then get() will raise an
ItemInterpreterDestroyed exception if the original interpreter
has been destroyed.  This does not otherwise affect the queue;
the next call to put() will work like normal, returning the next
item in the queue.

If "unbound" is UNBOUND_REMOVE then the item will be removed
from the queue as soon as the original interpreter is destroyed.
Be aware that this will introduce an imbalance between put()
and get() calls.

If "unbound" is UNBOUND then it is returned by get() in place
of the unbound item.
Nr   "timeout value must be non-negative)r0   r2   r3   r1   r&   r>   
ValueErrortimepickledumpsr4   putrE   r   sleep)
rK   objtimeoutr,   r%   rv   r6   r7   endexcs
             r   r}   	Queue.put   s    l ?))C"),xC?JI+G4JI'lG{ #EGG))+'C(?,,s#CDHHc	:   #&499;#+=

6""# s   "B> >
D3D  D)r,   r%   c                
   Uc  U R                   nOU(       a  [        O[        nUc  U R                  u  nO[	        U5      u  nU[        L a  [
        R                  " U5      n[        R                  " U R                  XU5        g r#   )
r0   r2   r3   r1   r&   r{   r|   r4   r}   rE   )rK   r   r,   r%   r6   r7   s         r   
put_nowaitQueue.put_nowait   s^    ?))C"),xC?JI+G4JI(?,,s#CDHHc	2r   )rv   c                   Ub4  [        U5      nUS:  a  [        S5      e[        R                  " 5       U-   n  [        R                  " U R
                  5      u  pEn Ub  Ub   [        U5      5       e[        U5      $ U[        :X  a  [        R                  " U5      nU$ U[        :X  d   eU$ ! [         a=  nUb  [        R                  " 5       W:  a  e [        R                  " U5         SnAOSnAff = fM  )zReturn the next object from the queue.

This blocks while the queue is empty.

If the next item's original interpreter has been destroyed
then the "next object" is determined by the value of the
"unbound" argument to put().
Nr   rx   )r>   ry   rz   r4   getrE   r   r~   reprr+   r3   r{   loadsr2   )rK   r   rv   r   r   r6   r7   r   s           r   r   	Queue.get  s     'lG{ #EGG))+'C&-kk$((&;#)  ;)S	);#I..(?,,s#C 
 ,&&&
  #&499;#+=

6""# s   #B/ /
C693C11C6c                     [         R                  " U R                  5      u  pnUb  Ub   [	        U5      5       e[        U5      $ U[        :X  a  [        R                  " U5      nU$ U[        :X  d   eU$ ! [         a  ne SnAff = f)z}Return the next object from the channel.

If the queue is empty then raise QueueEmpty.  Otherwise this
is the same as get().
N)
r4   r   rE   r   r   r+   r3   r{   r   r2   )rK   r   r6   r7   r   s        r   
get_nowaitQueue.get_nowait%  s    	")++dhh"7Ci  ;)S	);#I..(?,,s#C 
 ,&&&
  		s   #A6 6
B BB)r0   rE   rg   r1   r#   )r   r   r   r   r   rD   rQ   rW   r[   r_   rb   propertyrH   r5   rm   rq   rl   r}   r   r   r   r   __classcell__)rL   s   @r   r   r   ]   s    $$(4  43   ! !!)+MM^ *.t 3  D r   r   )r   )!r   r{   r!   rz   weakref_interpqueuesr4    r   r   r   r   r   __all__Emptyr   Fullr   r   r2   r3   UnboundItem	singletonr   r	   r&   r+   r
   r   WeakValueDictionaryrA   r   _register_heap_typesr   r   r   <module>r      s    1      U[[ 
EJJ .z+DD.
  
"
"
,
,Wh
?32W 2&; ++-Y Yx   UJ	 :r   