+
    DfjZ                    t  a  0 t $ R t^ RIHt ^ RIHtHt ^ RIHtH	t	H
t
HtHtHt ]'       d   ^ RIt^ RIHt ^RIHt ^RIHt  ! R R	]4      t]P,                  t]! R
4      t]! R4      t ! R R]],          4      tR]R&   ]t]! ]4       ! R R4      4       t ! R R]4      t]! ]4       ! R R4      4       t R# )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                  $    ] tR t^t]! 4       tRtR# )Stop N)__name__
__module____qualname____firstlineno__r   Thread__static_attributes__r       @/usr/lib/python3/dist-packages/twisted/_threads/_threadworker.pyr   r      s	    VFr   r   TUc                  .    ] tR t^ tR R ltR R ltRtR# )SimpleQueuec                    V ^8  d   QhRRRR/# )   itemr   returnNoner   )formats   "r   __annotate__SimpleQueue.__annotate__!   s       d r   c                	    R # Nr   )selfr   s   &&r   putSimpleQueue.put!       r   c                   V ^8  d   QhRR/# )r   r    r   r   )r"   s   "r   r#   r$   $   s      Q r   c                	    R # r&   r   r'   s   &r   getSimpleQueue.get$   r*   r   r   N)r   r   r   r   r(   r.   r   r   r   r   r   r            r   r   z/Callable[[Callable[[], T | U], U], Iterator[T]]	smartiterc                  >    ] tR t^-tRtR R ltR R ltR R ltRtR	# )
ThreadWorkerz
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                    V ^8  d   QhRRRR/# )r   startThreadz(Callable[[Callable[[], object]], object]queuez8SimpleQueue[Callable[[], object] | Literal[Stop.Thread]]r   )r"   s   "r   r#   ThreadWorker.__annotate__7   s      = Hr   c                V   a SV n         \        4       V n        R V3R llpV! V4       R# )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 ^8  d   QhRR/# r   r    r!   r   )r"   s   "r   r#   +ThreadWorker.__init__.<locals>.__annotate__I   s     	 	d 	r   c                 X   < \        SP                  \        4       F
  p V ! 4        K  	  R # r&   )r1   r.   
StopThread)taskr6   s    r   work#ThreadWorker.__init__.<locals>.workI   s    !%))Z8 9r   N)_qr   _hasQuit)r'   r5   r6   r?   s   &&f r   __init__ThreadWorker.__init__7   s)     	 	 	Dr   c                    V ^8  d   QhRRRR/# )r   r>   Callable[[], None]r    r!   r   )r"   s   "r   r#   r7   O   s      ) d r   c                p    V P                   P                  4        V P                  P                  V4       R# )zu
Perform the given task on the thread owned by this L{ThreadWorker}.

@param task: the function to call on a thread.
N)rB   checkrA   r(   )r'   r>   s   &&r   doThreadWorker.doO   s$     	Dr   c                   V ^8  d   QhRR/# r:   r   )r"   s   "r   r#   r7   X   s        d  r   c                x    V P                   P                  4        V P                  P                  \        4       R# )zD
Reject all future work and stop the thread started by C{__init__}.
N)rB   setrA   r(   r=   r-   s   &r   quitThreadWorker.quitX   s$     	Jr   )rB   rA   N	r   r   r   r   __doc__rC   rI   rN   r   r   r   r   r3   r3   -   s    0   r   r3   c                  .    ] tR t^btR R ltR R ltRtR# )
SimpleLockc                   V ^8  d   QhRR/# )r   r    boolr   )r"   s   "r   r#   SimpleLock.__annotate__c          r   c                	    R # r&   r   r-   s   &r   acquireSimpleLock.acquirec   r*   r   c                   V ^8  d   QhRR/# r:   r   )r"   s   "r   r#   rV   f   rW   r   c                	    R # r&   r   r-   s   &r   releaseSimpleLock.releasef   r*   r   r   N)r   r   r   r   rY   r]   r   r   r   r   rS   rS   b   r0   r   rS   c                  >    ] tR t^jtRtR R ltR R ltR R ltRtR	# )

LockWorkerz=
An L{IWorker} implemented based on a mutual-exclusion lock.
c                    V ^8  d   QhRRRR/# )r   lockrS   localzthreading.localr   )r"   s   "r   r#   LockWorker.__annotate__p   s      Z  r   c                <    \        4       V n        Wn        W n        R# )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'   rb   rc   s   &&&r   rC   LockWorker.__init__p   s     V
(,
r   c                    V ^8  d   QhRRRR/# )r   r?   rF   r    r!   r   )r"   s   "r   r#   rd   }   s     ! !) !d !r   c                   V P                   pV P                  pV P                  P                  4        \	        VRR4      pVfp   Vf   Q R4       h. ;qCn        VP                  V4       VP                  4         V'       d   VP                  ^ 4      ! 4        K    VP                  4        RVn        R# VP                  V4       R#   TP                  4        RTn        i ; i)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())
rg   rh   rf   rH   getattrrl   appendrY   popr]   )r'   r?   rb   rc   rl   s   &&   r   rI   LockWorker.do}   s     zz

%D1?#C%CC#&((GmNN4 LLN%KKN$   $NN4   $s   9C C Cc                   V ^8  d   QhRR/# r:   r   )r"   s   "r   r#   rd      s      d r   c                H    V P                   P                  4        RV n        R# )z
Quit this L{LockWorker}.
N)rf   rM   rg   r-   s   &r   rN   LockWorker.quit   s     	


r   )rh   rg   rf   NrP   r   r   r   r`   r`   j   s    !4 r   r`   )!__conditional_annotations__rQ   
__future__r   enumr   r   typingr   r   r   r   r	   r
   	threadingzope.interfacer   _conveniencer   	_ithreadsr   r   r   r=   r   r   r   __annotations__iterr1   r3   rS   r`   )rt   s   @r   <module>r~      s   
 #  P P &  '4  [[
CLCL(1+  ; :	 1  1  1 h  1 1 1r   