ó
    Ö›‘hZ  ã                  ób  • % S r SSKJr  SSKJrJr  SSKJrJrJ	r	J
r
JrJr  \(       a  SSKrSSKJr  SSKJr  SS	KJr   " S
 S\5      r\R*                  r\" S5      r\" S5      r " S S\\   5      rS\S'   \r\" \5       " S S5      5       r " S S\5      r\" \5       " S S5      5       rg)zE
Implementation of an L{IWorker} based on native threads and queues.
é    )Úannotations)ÚEnumÚauto)ÚTYPE_CHECKINGÚCallableÚIteratorÚLiteralÚProtocolÚTypeVarN)Úimplementeré   )ÚQuit)ÚIExclusiveWorkerc                  ó"   • \ rS rSr\" 5       rSrg)ÚStopé   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   ÚThreadÚ__static_attributes__r   ó    ÚbC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/_threads/_threadworker.pyr   r      s	   † Ù‹VƒFr   r   ÚTÚUc                  ó(   • \ rS rSrSS jrSS jrSrg)ÚSimpleQueueé    c                ó   • g ©Nr   )ÚselfÚitems     r   ÚputÚSimpleQueue.put!   ó   € Ør   c                ó   • g r"   r   ©r#   s    r   ÚgetÚSimpleQueue.get$   r'   r   r   N)r$   r   ÚreturnÚNone)r,   r   )r   r   r   r   r%   r*   r   r   r   r   r   r       ó   † ô÷r   r   z/Callable[[Callable[[], T | U], U], Iterator[T]]Ú	smartiterc                  ó>   • \ rS rSrSr    SS jrS	S jrS
S jrSrg)ÚThreadWorkeré-   zê
An L{IExclusiveWorker} implemented based on a single thread and a queue.

This worker ensures exclusivity (i.e. it is an L{IExclusiveWorker} and not
an L{IWorker}) by performing all of the work passed to C{do} on the I{same}
thread.
c                óR   ^• TU l         [        5       U l        SU4S jjnU" U5        g)a   
Create a L{ThreadWorker} with a function to start a thread and a queue
to use to communicate with that thread.

@param startThread: a callable that takes a callable to run in another
    thread.

@param queue: A L{Queue} to use to give tasks to the thread created by
    C{startThread}.
c                 óV   >• [        TR                  [        5       H
  n U " 5         M     g r"   )r/   r*   Ú
StopThread)ÚtaskÚqueues    €r   ÚworkÚ#ThreadWorker.__init__.<locals>.workI   s   ø€ Ü! %§)¡)¬ZÖ8�Ù–ò 9r   N©r,   r-   )Ú_qr   Ú_hasQuit)r#   ÚstartThreadr7   r8   s     ` r   Ú__init__ÚThreadWorker.__init__7   s$   ø€ ð ˆŒÜ›ˆŒ÷	ñ 	�DÕr   c                ón   • U R                   R                  5         U R                  R                  U5        g)zu
Perform the given task on the thread owned by this L{ThreadWorker}.

@param task: the function to call on a thread.
N)r<   Úcheckr;   r%   )r#   r6   s     r   ÚdoÚThreadWorker.doO   s$   € ð 	�‰×ÑÔØ�‰�‰�DÕr   c                óv   • U R                   R                  5         U R                  R                  [        5        g)zD
Reject all future work and stop the thread started by C{__init__}.
N)r<   Úsetr;   r%   r5   r)   s    r   ÚquitÚThreadWorker.quitX   s$   € ð 	�‰×ÑÔØ�‰�‰”JÕr   )r<   r;   N)r=   z(Callable[[Callable[[], object]], object]r7   z8SimpleQueue[Callable[[], object] | Literal[Stop.Thread]])r6   úCallable[[], None]r,   r-   r:   ©	r   r   r   r   Ú__doc__r>   rB   rF   r   r   r   r   r1   r1   -   s)   † ñðà=ðð Hôô0÷ r   r1   c                  ó(   • \ rS rSrSS jrSS jrSrg)Ú
SimpleLockéb   c                ó   • g r"   r   r)   s    r   ÚacquireÚSimpleLock.acquirec   r'   r   c                ó   • g r"   r   r)   s    r   ÚreleaseÚSimpleLock.releasef   r'   r   r   N)r,   Úboolr:   )r   r   r   r   rO   rR   r   r   r   r   rL   rL   b   r.   r   rL   c                  ó6   • \ rS rSrSrSS jrS	S jrS
S jrSrg)Ú
LockWorkeréj   z=
An L{IWorker} implemented based on a mutual-exclusion lock.
c                ó:   • [        5       U l        Xl        X l        g)z¯
@param lock: A mutual-exclusion lock, with C{acquire} and C{release}
    methods.
@type lock: L{threading.Lock}

@param local: Local storage.
@type local: L{threading.local}
N)r   Ú_quitÚ_lockÚ_local)r#   ÚlockÚlocals      r   r>   ÚLockWorker.__init__p   s   € ô “VˆŒ
Ø(,Œ
Ø�r   c                óÆ  • U R                   nU R                  nU R                  R                  5         [	        USS5      nUcr  Uc   S5       e/ =oCl        UR                  U5        UR                  5          U(       a  UR                  S5      " 5         U(       a  M  UR                  5         SUl        gUR                  U5        g! UR                  5         SUl        f = f)zÇ
Do the given work on this thread, with the mutex acquired.  If this is
called re-entrantly, return and wait for the outer invocation to do the
work.

@param work: the work to do with the lock held.
ÚworkingNzLockWorker used after quit()r   )
rZ   r[   rY   rA   Úgetattrr`   ÚappendrO   ÚpoprR   )r#   r8   r\   r]   r`   s        r   rB   ÚLockWorker.do}   s¹   € ð �z‰zˆØ—‘ˆØ�
‰
×ÑÔÜ˜% ¨DÓ1ˆØ‰?ØÑ#ÐCÐ%CÓCÐ#Ø&(Ð(ˆG”mØ�N‰N˜4Ô Ø�L‰LŒNð%ÞØ—K‘K ”NÔ$÷ �gð —‘”Ø $�•à�N‰N˜4Õ øð —‘”Ø $�•ús   Á7$C ÃC c                óF   • U R                   R                  5         SU l        g)z
Quit this L{LockWorker}.
N)rY   rE   rZ   r)   s    r   rF   ÚLockWorker.quit—   s   € ð 	�
‰
�‰ÔØˆ�
r   )r[   rZ   rY   N)r\   rL   r]   zthreading.local)r8   rH   r,   r-   r:   rI   r   r   r   rV   rV   j   s   † ñôô!÷4r   rV   ) rJ   Ú
__future__r   Úenumr   r   Útypingr   r   r   r	   r
   r   Ú	threadingÚzope.interfacer   Ú_conveniencer   Ú	_ithreadsr   r   r   r5   r   r   r   Ú__annotations__Úiterr/   r1   rL   rV   r   r   r   Ú<module>rp      s¸   ðò
õ #ç ß P× PæÛå &å Ý 'ôˆ4ô ð �[‰[€
áˆCƒL€ÙˆCƒL€ô�(˜1‘+ô ð ;Ó :Ø€	ñ ÐÓ÷1 ð 1 ó ð1 ôh�ô ñ ÐÓ÷1ð 1ó ñ1r   