+
    üÐj�V  ã                   óZ  € R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RI	H
t
HtHtHt ^ RIHt  ! R R4      t]P"                  ! ]4        ! R R]P$                  4      t ! R	 R
]P$                  4      t ! R R]P*                  4      t ! R R4      t ! R R]P$                  4      tR# )z(
Tests for L{twisted.python.threadpool}
N)ÚTeamÚcreateMemoryWorker)ÚcontextÚfailureÚ
threadableÚ
threadpool)Úunittestc                   ó6   a € ] tR t^t o ^ tR tR tR.tRtV t	R# )ÚSynchronizationc                ó`   € Wn         W n        \        P                  ! 4       V n        . V n        R # ©N)ÚNÚwaitingÚ	threadingÚLockÚlockÚruns)Úselfr   r   s   &&&Ú>/usr/lib/python3/dist-packages/twisted/test/test_threadpool.pyÚ__init__ÚSynchronization.__init__   s!   € ØŒØŒÜ—N’NÓ$ˆŒ	ØˆŽ	ó    c                ó:  € V P                   P                  R 4      '       dT   \        V P                  4      ^,          '       g   \        P
                  ! R4       V P                   P                  4        MV ;P                  ^,          un        V P                   P                  4        V P                  P                  R4       \        V P                  4      V P                  8X  d   V P                  P                  4        V P                   P                  4        R# )Fg-Cëâ6*?N)r   ÚacquireÚlenr   ÚtimeÚsleepÚreleaseÚfailuresÚappendr   r   ©r   s   &r   ÚrunÚSynchronization.run   s°   € ð �9‰9×Ñ˜U×#Ò#Ü�t—y‘y“> A×%Ô%ô —
’
˜6Ô"Ø�I‰I×ÑÕà�MŠM˜QÕ�Mð
 	�	‰	×ÑÔØ�	‰	×Ñ˜ÔÜˆt�y‰y‹>˜TŸV™VÔ#Ø�L‰L× Ñ Ô"Ø�	‰	×ÑÖr   r!   )r   r   r   r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r   r!   ÚsynchronizedÚ__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r
   r
      s   ø‡ € Ø€Hòòð0 �7†Lr   r
   c                   ó¢   a € ] tR t^;t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tV 3R lR ltRtV tR# )ÚThreadPoolTestsz
Test threadpools.
c                ó   € ^# )z4
Return number of seconds to wait before giving up.
© r    s   &r   Ú
getTimeoutÚThreadPoolTests.getTimeout@   ó   € ñ r   c                ó°   € \        R 4      pV F3  pVP                  R4      '       d    R# \        P                  ! R4       K5  	  V P	                  R4       R# )i@B Fgñhãˆµøä>z%A long time passed without succeedingN)Úranger   r   r   Úfail)r   r   ÚitemsÚis   &&  r   Ú_waitForLockÚThreadPoolTests._waitForLockF   sB   € Ü�g“ˆÛˆAØ�|‰|˜E×"Ò"ÚÜ�JŠJ�tÖñ ð
 �I‰IÐ=Ö>r   c                ó¤   € \         P                  ! ^^4      pV P                  VP                  ^4       V P                  VP                  ^4       R# )za
L{ThreadPool.min} and L{ThreadPool.max} are set to the values passed to
L{ThreadPool.__init__}.
N)r   Ú
ThreadPoolÚassertEqualÚminÚmax©r   Úpools   & r   Útest_attributesÚThreadPoolTests.test_attributesO   s>   € ô
 ×$Ò$ R¨Ó,ˆØ×Ñ˜Ÿ™ 2Ô&Ø×Ñ˜Ÿ™ 2Ö&r   c                óì  € \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  \        VP                  4      ^ 4       \         P                  ! ^^
4      pV P                  \        VP                  4      ^ 4       VP                  4        V P                  VP                  4       V P                  \        VP                  4      ^4       R# )zF
L{ThreadPool.start} creates the minimum number of threads specified.
N)r   r;   ÚstartÚ
addCleanupÚstopr<   r   Úthreadsr?   s   & r   Ú
test_startÚThreadPoolTests.test_startX   s¥   € ô ×$Ò$ Q¨Ó*ˆØ�
‰
ŒØ�‰˜Ÿ	™	Ô"Ø×Ñœ˜TŸ\™\Ó*¨AÔ.ä×$Ò$ Q¨Ó+ˆØ×Ñœ˜TŸ\™\Ó*¨AÔ.Ø�
‰
ŒØ�‰˜Ÿ	™	Ô"Ø×Ñœ˜TŸ\™\Ó*¨AÖ.r   c                óà   € \         P                  ! ^ ^4      pVP                  4        VP                  4        VP	                  ^4       V P                  \        VP                  4      ^ 4       R# )zx
L{ThreadPool.adjustPoolsize} only modifies the pool size and does not
start new workers while the pool is not running.
N)r   r;   rD   rF   ÚadjustPoolsizer<   r   rG   r?   s   & r   Útest_adjustingWhenPoolStoppedÚ-ThreadPoolTests.test_adjustingWhenPoolStoppedg   sO   € ô
 ×$Ò$ Q¨Ó*ˆØ�
‰
ŒØ�	‰	ŒØ×Ñ˜AÔØ×Ñœ˜TŸ\™\Ó*¨AÖ.r   c                óˆ  € \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  VP                  . 4       R p ! R R4      pV! 4       p\        P                  ! V4      p\        P                  ! V4      pVP                  W$4       \        P                  ! 4       pVP                  VP                  4       VP                  V P                  4       4       ??\        P                   ! 4        V P#                  V! 4       4       V P#                  V! 4       4       R# )zÔ
Test that creating threads in the threadpool with application-level
objects as arguments doesn't results in those objects never being
freed, with the thread maintaining a reference to them as long as it
exists.
c                 ó   € R # r   r/   )Úargs   &r   ÚworkerÚ<ThreadPoolTests.test_threadCreationArguments.<locals>.worker�   s   € Ùr   c                   ó   € ] tR t^…tRtR# )Ú:ThreadPoolTests.test_threadCreationArguments.<locals>.Dumbr/   N©r#   r$   r%   r&   r(   r/   r   r   ÚDumbrT   …   ó   † Ûr   rV   N)r   r;   rD   rE   rF   r<   rG   ÚweakrefÚrefÚcallInThreadr   ÚEventÚsetÚwaitr0   ÚgcÚcollectÚassertIsNone)r   ÚtprQ   rV   ÚuniqueÚ	workerRefÚ	uniqueRefÚevents   &       r   Útest_threadCreationArgumentsÚ,ThreadPoolTests.test_threadCreationArgumentsr   sç   € ô ×"Ò" 1 aÓ(ˆØ
�‰Œ
Ø�‰˜Ÿ™Ô ð 	×Ñ˜Ÿ™ RÔ(ò	÷	ñ 	ñ “ˆä—K’K Ó'ˆ	Ü—K’K Ó'ˆ	ð 	�‰˜Ô'ô —’Ó!ˆØ
�‰˜Ÿ	™	Ô"Ø�
‰
�4—?‘?Ó$Ô%àØÜ
�
Š
ŒØ×Ñ™)›+Ô&Ø×Ñ™)›+Ö&r   c                óê  a aaaa	a
aa€ \         P                  ! ^ ^4      pVP                  4        S P                  VP                  4       S P                  VP                  . 4       / o	\        P                  ! 4       o\        P                  ! 4       o. o
VVV	V
V VV3R lpV3R lp ! R R4      oS! 4       p\        P                  ! V4      p\        P                  ! V4      o\        P                  ! V4      oVP                  W#WDR7       ??SP                  4        SP                  S P                  4       4       \        P                   ! 4        S P#                  S! 4       4       S P#                  S! 4       4       ?\        P                   ! 4        S P#                  V! 4       4       S P#                  S
^ ,          ! 4       4       S P                  \%        S	P'                  4       4      RR.4       R# )zM
As C{test_threadCreationArguments} above, but for
callInThreadWithCallback.
c                 ó  <€ \         P                  ! 4        SP                  SP                  4       4       S! 4       SR &   S! 4       SR&   SP	                  4        SP                  \        P                  ! V4      4       R# )rc   rd   N)r^   r_   r]   r0   r\   r   rX   rY   )	ÚsuccessÚresultÚonResultDoneÚonResultWaitÚrefdictÚ	resultRefr   rd   rc   s	   &&€€€€€€€r   ÚonResultÚVThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.onResult²   s^   ø€ ô �JŠJŒLØ×Ñ˜dŸo™oÓ/Ô0Ù#,£;ˆG�KÑ Ù#,£;ˆG�KÑ Ø×ÑÔØ×ÑœWŸ[š[¨Ó0Ö1r   c                 ó   <€ S! 4       # r   r/   )rP   ÚtestrV   s   &&€r   rQ   ÚTThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.worker½   s
   ø€ Ù“6ˆMr   c                   ó   € ] tR t^ÁtRtR# )ÚRThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallback.<locals>.Dumbr/   NrU   r/   r   r   rV   rv   Á   rW   r   rV   ©rs   N)r   r;   rD   rE   rF   r<   rG   r   r[   rX   rY   ÚcallInThreadWithCallbackr\   r]   r0   r^   r_   r`   ÚlistÚvalues)r   ra   rp   rQ   rb   ÚonResultRefrV   rl   rm   rn   ro   rd   rc   s   f     @@@@@@@r   Ú4test_threadCreationArgumentsCallInThreadWithCallbackÚDThreadPoolTests.test_threadCreationArgumentsCallInThreadWithCallbackœ   sq  ÿ€ ô ×"Ò" 1 aÓ(ˆØ
�‰Œ
Ø�‰˜Ÿ™Ô ð 	×Ñ˜Ÿ™ RÔ(ð ˆä —’Ó(ˆÜ —’Ó(ˆàˆ	÷	2ó 	2õ	÷	ñ 	ñ “ˆä—k’k (Ó+ˆÜ—K’K Ó'ˆ	Ü—K’K Ó'ˆ	ð 	×#Ñ# H°fÐ#ÔJàØð 	×ÑÔà×Ñ˜$Ÿ/™/Ó+Ô,Ü
�
Š
Œà×Ñ™)›+Ô&Ø×Ñ™)›+Ô&ð Ü
�
Š
ŒØ×Ñ™+›-Ô(Ø×Ñ˜) Až,›.Ô)ð 	×Ñœ˜gŸn™nÓ.Ó/°$¸°Ö>r   c                óh  € \         P                  ! ^^4      pV P                  VP                  ^4       V P                  VP                  ^4       \
        P                  ! \
        P                  ! V4      4      pV P                  VP                  ^4       V P                  VP                  ^4       R# )zm
Threadpools can be pickled and unpickled, which should preserve the
number of threads and other parameters.
N)r   r;   r<   r=   r>   ÚpickleÚloadsÚdumps)r   r@   Úcopys   &  r   Útest_persistenceÚ ThreadPoolTests.test_persistenceæ   s   € ô
 ×$Ò$ Q¨Ó+ˆà×Ñ˜Ÿ™ 1Ô%Ø×Ñ˜Ÿ™ 2Ô&ô �|Š|œFŸLšL¨Ó.Ó/ˆà×Ñ˜Ÿ™ 1Ô%Ø×Ñ˜Ÿ™ 2Ö&r   c                ó”  € ^
p\         P                  ! 4       pVP                  4        V P                  VP                  4       \
        P                  ! 4       pVP                  4        \        W$4      p\        V4       F  pV! W54       K  	  V P                  V4       V P                  VP                  RVP                   R24       R# )zˆ
Test synchronization of calls made with C{method}, which should be
one of the mechanisms of the threadpool to execute work in threads.
zrun() re-entered z timesN)r   r;   rD   rE   rF   r   r   r   r
   r4   r8   ÚassertFalser   )r   Úmethodr   ra   r   Úactorr7   s   &&     r   Ú_threadpoolTestÚThreadPoolTests._threadpoolTestö   s™   € ð ˆä×"Ò"Ó$ˆØ
�‰Œ
Ø�‰˜Ÿ™Ô ä—.’.Ó"ˆØ�‰ÔÜ Ó+ˆä�q–ˆAÙ�2Öñ ð 	×Ñ˜'Ô"à×Ñ˜Ÿ™Ð+<¸U¿^¹^Ð<LÈFÐ)SÖTr   c                ó&   € V P                  R 4      # )z/
Call C{_threadpoolTest} with C{callInThread}.
c                 ó8   € V P                  VP                  4      # r   )rZ   r!   )ra   rˆ   s   &&r   Ú<lambda>Ú3ThreadPoolTests.test_callInThread.<locals>.<lambda>  s   € °b·o±oÀeÇiÁiÔ6Pr   )r‰   r    s   &r   Útest_callInThreadÚ!ThreadPoolTests.test_callInThread  s   € ð ×#Ñ#Ñ$PÓQÐQr   c                ó  a€  ! R R\         4      oV3R lp\        P                  ! ^ ^4      pVP                  V4       VP	                  4        VP                  4        V P                  S4      pV P                  \        V4      ^4       R# )zQ
L{ThreadPool.callInThread} logs exceptions raised by the callable it
is passed.
c                   ó   € ] tR tRtRtR# )Ú<ThreadPoolTests.test_callInThreadException.<locals>.NewErrori  r/   NrU   r/   r   r   ÚNewErrorr“     rW   r   r”   c                  ó   <€ S ! 4       hr   r/   ©r”   s   €r   Ú
raiseErrorÚ>ThreadPoolTests.test_callInThreadException.<locals>.raiseError  ó   ø€ Ù“*Ðr   N)	Ú	Exceptionr   r;   rZ   rD   rF   ÚflushLoggedErrorsr<   r   )r   r—   ra   Úerrorsr”   s   &   @r   Útest_callInThreadExceptionÚ*ThreadPoolTests.test_callInThreadException  sj   ø€ ô	”yô 	õ	ô ×"Ò" 1 aÓ(ˆØ
�‰˜
Ô#Ø
�‰Œ
Ø
�‰Œ	à×'Ñ'¨Ó1ˆØ×Ñœ˜V› aÖ(r   c                óª  aa€ \         P                  ! 4       oSP                  4        . oVV3R lp\        P                  ! ^ ^4      pVP                  VR 4       VP                  4         V P                  S4       VP                  4        V P                  S^ ,          4       V P                  S^,          R4       R#   TP                  4        i ; i)z 
L{ThreadPool.callInThreadWithCallback} calls C{onResult} with a
two-tuple of C{(True, result)} where C{result} is the value returned
by the callable supplied.
c                 ól   <€ SP                  4        SP                  V 4       SP                  V4       R # r   ©r   r   ©rj   rk   ÚresultsÚwaiters   &&€€r   rp   Ú?ThreadPoolTests.test_callInThreadWithCallback.<locals>.onResult5  ó%   ø€ Ø�N‰NÔØ�N‰N˜7Ô#Ø�N‰N˜6Ö"r   c                  ó   € R # rw   r/   r/   r   r   r�   Ú?ThreadPoolTests.test_callInThreadWithCallback.<locals>.<lambda>;  s   € ±fr   rs   N)r   r   r   r   r;   rx   rD   r8   rF   Ú
assertTruer<   )r   rp   ra   r£   r¤   s   &  @@r   Útest_callInThreadWithCallbackÚ-ThreadPoolTests.test_callInThreadWithCallback*  sŸ   ù€ ô —’Ó!ˆØ�‰Ôàˆö	#ô
 ×"Ò" 1 aÓ(ˆØ
×#Ñ# H©nÔ=Ø
�‰Œ
ð	Ø×Ñ˜fÔ%à�G‰GŒIà�‰˜ �
Ô#Ø×Ñ˜ � VÖ,øð �G‰G�Iús   Á,C  Ã Cc                óF  aaa€  ! R R\         4      oV3R lp\        P                  ! 4       oSP                  4        . oVV3R lp\        P
                  ! ^ ^4      pVP                  W!4       VP                  4         V P                  S4       VP                  4        V P                  S^ ,          4       V P                  S^,          \        P                  4       V P                  \        S^,          P                   S4      4       R#   TP                  4        i ; i)z­
L{ThreadPool.callInThreadWithCallback} calls C{onResult} with a
two-tuple of C{(False, failure)} where C{failure} represents the
exception raised by the callable supplied.
c                   ó   € ] tR tRtRtR# )ÚRThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.NewErroriM  r/   NrU   r/   r   r   r”   r®   M  rW   r   r”   c                  ó   <€ S ! 4       hr   r/   r–   s   €r   r—   ÚTThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.raiseErrorP  r™   r   c                 ól   <€ SP                  4        SP                  V 4       SP                  V4       R # r   r¡   r¢   s   &&€€r   rp   ÚRThreadPoolTests.test_callInThreadWithCallbackExceptionInCallback.<locals>.onResultX  r¦   r   N)rš   r   r   r   r   r;   rx   rD   r8   rF   r†   ÚassertIsInstancer   ÚFailurer©   Ú
issubclassÚtype)r   r—   rp   ra   r”   r£   r¤   s   &   @@@r   Ú0test_callInThreadWithCallbackExceptionInCallbackÚ@ThreadPoolTests.test_callInThreadWithCallbackExceptionInCallbackF  sÏ   ú€ ô	”yô 	õ	ô —’Ó!ˆØ�‰Ôàˆö	#ô
 ×"Ò" 1 aÓ(ˆØ
×#Ñ# HÔ9Ø
�‰Œ
ð	Ø×Ñ˜fÔ%à�G‰GŒIà×Ñ˜ �Ô$Ø×Ñ˜g a�j¬'¯/©/Ô:Ø�‰œ
 7¨1¥:§?¡?°HÓ=Ö>øð	 �G‰G�Iús   Â D ÄD c                óT  aa€  ! R R\         4      o\        P                  ! 4       pVP                  4        . oVV3R lp\        P
                  ! ^ ^4      pVP                  VR 4       VP                  VP                  4       VP                  4         V P                  V4       VP                  4        V P                  S4      pV P                  \        V4      ^4       V P                  S^ ,          4       V P!                  S^,          4       R#   TP                  4        i ; i)zR
L{ThreadPool.callInThreadWithCallback} logs the exception raised by
C{onResult}.
c                   ó   € ] tR tRtRtR# )ÚRThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.NewErrorip  r/   NrU   r/   r   r   r”   r»   p  rW   r   r”   c                 óV   <€ SP                  V 4       SP                  V4       S! 4       hr   )r   )rj   rk   r”   r£   s   &&€€r   rp   ÚRThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.onResultx  s#   ø€ Ø�N‰N˜7Ô#Ø�N‰N˜6Ô"Ù“*Ðr   c                  ó   € R # r   r/   r/   r   r   r�   ÚRThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResult.<locals>.<lambda>~  s   € ±dr   N)rš   r   r   r   r   r;   rx   rZ   r   rD   r8   rF   r›   r<   r   r©   r`   )r   r¤   rp   ra   rœ   r”   r£   s   &    @@r   Ú0test_callInThreadWithCallbackExceptionInOnResultÚ@ThreadPoolTests.test_callInThreadWithCallbackExceptionInOnResultj  sÝ   ù€ ô	”yô 	ô —’Ó!ˆØ�‰Ôàˆö	ô
 ×"Ò" 1 aÓ(ˆØ
×#Ñ# H©lÔ;Ø
�‰˜Ÿ™Ô'Ø
�‰Œ
ð	Ø×Ñ˜fÔ%à�G‰GŒIà×'Ñ'¨Ó1ˆØ×Ñœ˜V› aÔ(à�‰˜ �
Ô#Ø×Ñ˜' !�*Ö%øð �G‰G�Iús   ÂD ÄD'c                ó¬  aa€ . o\         P                  ! 4       oVV3R lpV3R lp\        P                  ! ^ ^4      pVP	                  W4       VP                  4        V P                  VP                  4       SP                  V P                  4       4       V P                  \        S4      ^4       V P                  S^ ,          S^,          4       R# )zx
L{ThreadPool.callInThreadWithCallback} calls the function it is
given and the C{onResult} callback in the same thread.
c                 ó„   <€ SP                  \        P                  ! 4       P                  4       SP	                  4        R # r   )r   r   Úcurrent_threadÚidentr\   )rj   rk   re   Ú	threadIdss   &&€€r   rp   Ú5ThreadPoolTests.test_callbackThread.<locals>.onResult–  s)   ø€ Ø×ÑœY×5Ò5Ó7×=Ñ=Ô>Ø�I‰IŽKr   c                  ód   <€ S P                  \        P                  ! 4       P                  4       R # r   )r   r   rÄ   rÅ   )rÆ   s   €r   ÚfuncÚ1ThreadPoolTests.test_callbackThread.<locals>.funcš  s    ø€ Ø×ÑœY×5Ò5Ó7×=Ñ=Ö>r   N)r   r[   r   r;   rx   rD   rE   rF   r]   r0   r<   r   )r   rp   rÉ   ra   re   rÆ   s   &   @@r   Útest_callbackThreadÚ#ThreadPoolTests.test_callbackThread�  sš   ù€ ð
 ˆ	ä—’Ó!ˆö	õ	?ô ×"Ò" 1 aÓ(ˆØ
×#Ñ# HÔ3Ø
�‰Œ
Ø�‰˜Ÿ™Ô à�
‰
�4—?‘?Ó$Ô%Ø×Ñœ˜Y›¨Ô+Ø×Ñ˜ 1� y°¥|Ö4r   c                ó8  aa€ \         P                  P                  4       P                  R,          pRVR&   . o\        P
                  ! 4       oVV3R lpV3R lp\        P                  ! ^ ^4      pVP                  W#4       VP                  4        V P                  VP                  4       SP                  V P                  4       4       V P                  \        S4      ^4       V P                  VS^ ,          4       V P                  VS^,          4       R# )z‘
The context L{ThreadPool.callInThreadWithCallback} is invoked in is
shared by the context the callable and C{onResult} callback are
invoked in.
zthis must be presentÚtestingc                 ó¨   <€ \         P                  P                  4       P                  R,          pSP	                  V4       SP                  4        R# ©é   Néÿÿÿÿ)r   ÚtheContextTrackerÚcurrentContextÚcontextsr   r\   )rj   rk   ÚctxrÕ   re   s   && €€r   rp   Ú6ThreadPoolTests.test_callbackContext.<locals>.onResult³  s7   ø€ Ü×+Ñ+×:Ñ:Ó<×EÑEÀbÕIˆCØ�O‰O˜CÔ Ø�I‰IŽKr   c                  óˆ   <€ \         P                  P                  4       P                  R,          p SP	                  V 4       R# rÐ   )r   rÓ   rÔ   rÕ   r   )rÖ   rÕ   s    €r   rÉ   Ú2ThreadPoolTests.test_callbackContext.<locals>.func¸  s.   ø€ Ü×+Ñ+×:Ñ:Ó<×EÑEÀbÕIˆCØ�O‰O˜CÖ r   NrÒ   )r   rÓ   rÔ   rÕ   r   r[   r   r;   rx   rD   rE   rF   r]   r0   r<   r   )r   Úmyctxrp   rÉ   ra   rÕ   re   s   &    @@r   Útest_callbackContextÚ$ThreadPoolTests.test_callbackContext¦  sÓ   ù€ ô ×)Ñ)×8Ñ8Ó:×CÑCÀBÕGˆØ1ˆˆiÑàˆä—’Ó!ˆö	õ
	!ô ×"Ò" 1 aÓ(ˆØ
×#Ñ# HÔ3Ø
�‰Œ
Ø�‰˜Ÿ™Ô à�
‰
�4—?‘?Ó$Ô%à×Ñœ˜X›¨Ô*Ø×Ñ˜ ¨¥Ô,Ø×Ñ˜ ¨¥Ö,r   c                óB  € \         P                  ! 4       pVP                  4        \        P                  ! ^ ^4      pVP                  VP                  4       VP                  4         V P                  V4       VP                  4        R#   TP                  4        i ; i)z£
Work added to the threadpool before its start should be executed once
the threadpool is started: this is ensured by trying to release a lock
previously acquired.
N)
r   r   r   r   r;   rZ   r   rD   r8   rF   )r   r¤   ra   s   &  r   Útest_existingWorkÚ!ThreadPoolTests.test_existingWorkÇ  sk   € ô —’Ó!ˆØ�‰Ôä×"Ò" 1 aÓ(ˆØ
�‰˜Ÿ™Ô'Ø
�‰Œ
ð	Ø×Ñ˜fÔ%à�G‰GŽIøˆB�G‰G�Iús   Á)B ÂBc                óæ  aa€ \         P                  ! ^ ^4      pVP                  4        V P                  VP                  4       V P                  VP                  ^ 4       V P                  \        VP                  4      ^ 4       V P                  \        VP                  4      ^ 4       \        P                  ! 4       o\        P                  ! 4       oVV3R lpVP                  V4       SP                  ^
4       V P                  VP                  ^4       V P                  \        VP                  4      ^ 4       V P                  \        VP                  4      ^4       SP                  4        \        VP                  4      '       g   \        P                   ! R4       K3  V P                  \        VP                  4      ^4       V P                  \        VP                  4      ^ 4       R# )zc
As the worker receives and completes work, it transitions between
the working and waiting states.
c                  óJ   <€ SP                  4        S P                  ^
4       R# )é
   N)r\   r]   )ÚthreadFinishÚthreadWorkings   €€r   Ú_threadÚ;ThreadPoolTests.test_workerStateTransition.<locals>._threadë  s   ø€ Ø×ÑÔØ×Ñ˜bÖ!r   gü©ñÒMb@?N)r   r;   rD   rE   rF   r<   Úworkersr   ÚwaitersÚworkingr   r[   rZ   r]   r\   r   r   )r   r@   rå   rã   rä   s   &  @@r   Útest_workerStateTransitionÚ*ThreadPoolTests.test_workerStateTransitionÙ  sX  ù€ ô
 ×$Ò$ Q¨Ó*ˆØ�
‰
ŒØ�‰˜Ÿ	™	Ô"ð 	×Ñ˜Ÿ™ qÔ)Ø×Ñœ˜TŸ\™\Ó*¨AÔ.Ø×Ñœ˜TŸ\™\Ó*¨AÔ.ô "ŸšÓ)ˆÜ —’Ó(ˆö	"ð 	×Ñ˜'Ô"Ø×Ñ˜2ÔØ×Ñ˜Ÿ™ qÔ)Ø×Ñœ˜TŸ\™\Ó*¨AÔ.Ø×Ñœ˜TŸ\™\Ó*¨AÔ.ð 	×ÑÔÜ�d—l‘l×#Ò#Ü�JŠJ�vÖð 	×Ñœ˜TŸ\™\Ó*¨AÔ.Ø×Ñœ˜TŸ\™\Ó*¨AÖ.r   c                ó   <€ V ^8„  d   QhRR/# )é   ÚreturnNr/   )Úformatr+   s   "€r   Ú__annotate__ÚThreadPoolTests.__annotate__þ  s   ø€ ÷ 1ñ 1˜ñ 1r   c                óˆ   € \         P                  ! ^ ^4      pV P                  VP                  P	                  4       ^ 4       R# )z2
There is a property '_queue' for legacy purposes
N)r   r;   r<   Ú_queueÚqsizer?   s   & r   Útest_qÚThreadPoolTests.test_qþ  s3   € ô ×$Ò$ Q¨Ó*ˆØ×Ñ˜Ÿ™×*Ñ*Ó,¨aÖ0r   r/   N)r#   r$   r%   r&   Ú__doc__r0   r8   rA   rH   rL   rf   r|   rƒ   r‰   r�   r�   rª   r·   rÀ   rË   rÛ   rÞ   rê   rõ   r(   r)   r*   s   @r   r-   r-   ;   sw   ø‡ € ñòò?ò'ò/ò	/ò('òTH?òT'ò Uò4Rò)ò(-ò8"?òH!&òF5ò2-òBò$#/÷J1ö 1r   r-   c                   ó2   a € ] tR tRt o R tR tR tRtV tR# )ÚRaceConditionTestsi  c                óÖ   a € \         P                  ! ^ ^
4      S n         \        P                  ! 4       S n        S P                   P                  4        V 3R lpS P                  V4       R# )é    c                  ó@   <€ S P                   P                  4        S = R # r   )r   rF   r    s   €r   ÚdoneÚ&RaceConditionTests.setUp.<locals>.done  s   ø€ Ø�O‰O× Ñ Ô"Ø’r   N)r   r;   r   r[   re   rD   rE   )r   rý   s   f r   ÚsetUpÚRaceConditionTests.setUp  sH   ø€ Ü$×/Ò/°°2Ó6ˆŒÜ—_’_Ó&ˆŒ
Ø�‰×ÑÔõ	 ð 	�‰˜Ör   c                ó   € ^# )z-
A reasonable number of seconds to time out.
r/   r    s   &r   r0   ÚRaceConditionTests.getTimeout  r2   r   c                óž  € V P                  4       pV P                  P                  V P                  P                  4       V P                  P                  V4       V P                  P                  4        \        ^4       F2  pV P                  P                  V P                  P
                  4       K4  	  V P                  P                  V P                  P                  4       V P                  P                  V4       V P                  P                  4       '       g.   V P                  P	                  4        V P                  R4       R# R# )a-  
If multiple threads are waiting on an event (via blocking on something
in a callable passed to L{threadpool.ThreadPool.callInThread}), and
there is spare capacity in the threadpool, sending another callable
which will cause those to un-block to
L{threadpool.ThreadPool.callInThread} will reliably run that callable
and un-block the blocked threads promptly.

@note: This is not really a unit test, it is a stress-test.  You may
    need to run it with C{trial -u} to fail reliably if there is a
    problem.  It is very hard to regression-test for this particular
    bug - one where the thread pool may consider itself as having
    "enough capacity" when it really needs to spin up a new thread if
    it possibly can - in a deterministic way, since the bug can only be
    provoked by subtle race conditions.
z9'set' did not run in thread; timed out waiting on 'wait'.N)
r0   r   rZ   re   r\   r]   Úclearr4   ÚisSetr5   )r   Útimeoutr7   s   &  r   Útest_synchronizationÚ'RaceConditionTests.test_synchronization  sÏ   € ð" —/‘/Ó#ˆØ�‰×$Ñ$ T§Z¡Z§^¡^Ô4Ø�
‰
�‰˜Ô Ø�
‰
×ÑÔÜ�q–ˆAØ�O‰O×(Ñ(¨¯©¯©Ö9ñ à�‰×$Ñ$ T§Z¡Z§^¡^Ô4Ø�
‰
�‰˜Ô Ø�z‰z×Ñ×!Ò!Ø�J‰J�N‰NÔØ�I‰IÐQÖRñ "r   )re   r   N)	r#   r$   r%   r&   rÿ   r0   r  r(   r)   r*   s   @r   rù   rù     s   ø‡ € ò	ò÷Sð Sr   rù   c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )Ú
MemoryPooli6  zs
A deterministic threadpool that uses in-memory data structures to queue
work rather than threads to execute work.
c                ór   € Wn         W n        W0n        \        P                  P
                  ! V .VO5/ VB  R# )a\  
Initialize this L{MemoryPool} with a test case.

@param coordinator: a worker used to coordinate work in the L{Team}
    underlying this threadpool.
@type coordinator: L{twisted._threads.IExclusiveWorker}

@param failTest: A 1-argument callable taking an exception and raising
    a test-failure exception.
@type failTest: 1-argument callable taking (L{Failure}) and raising
    L{unittest.FailTest}.

@param newWorker: a 0-argument callable that produces a new
    L{twisted._threads.IWorker} provider on each invocation.
@type newWorker: 0-argument callable returning
    L{twisted._threads.IWorker}.
N)Ú_coordinatorÚ	_failTestÚ
_newWorkerr   r;   r   )r   ÚcoordinatorÚfailTestÚ	newWorkerÚargsÚkwargss   &&&&*,r   r   ÚMemoryPool.__init__<  s2   € ð$ (ÔØ!ŒØ#ŒÜ×Ñ×&Ò& tÐ=¨dÒ=°fÔ=r   c                ó`   a aa€ VV V3R lp\        S P                  VS P                  R7      oS# )ag  
Override testing hook to create a deterministic threadpool.

@param currentLimit: A 1-argument callable which returns the current
    threadpool size limit.

@param threadFactory: ignored in this invocation; a 0-argument callable
    that would produce a thread.

@return: a L{Team} backed by the coordinator and worker passed to
    L{MemoryPool.__init__}.
c                  ó–   <€ SP                  4       p V P                  V P                  ,           S! 4       8¼  d   R # SP                  4       # r   )Ú
statisticsÚbusyWorkerCountÚidleWorkerCountr  )ÚstatsÚcurrentLimitr   Úteams    €€€r   ÚrespectLimitÚ&MemoryPool._pool.<locals>.respectLimita  s<   ø€ ð —O‘OÓ%ˆEØ×%Ñ%¨×(=Ñ(=Õ=Á,Ã.ÔPÙØ—?‘?Ó$Ð$r   )r  ÚcreateWorkerÚlogException)r   r  r  )r   r  ÚthreadFactoryr  r  s   ff& @r   Ú_poolÚMemoryPool._poolS  s.   ú€ ÷	%ô Ø×)Ñ)Ø%ØŸ™ô
ˆð
 ˆr   )r  r  r  N)	r#   r$   r%   r&   r÷   r   r"  r(   r)   r*   s   @r   r
  r
  6  s   ø‡ € ñò
>÷.ð r   r
  c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )Ú
PoolHelperir  aÖ  
A L{PoolHelper} constructs a L{threadpool.ThreadPool} that doesn't actually
use threads, by using the internal interfaces in L{twisted._threads}.

@ivar performCoordination: a 0-argument callable that will perform one unit
    of "coordination" - work involved in delegating work to other threads -
    and return L{True} if it did any work, L{False} otherwise.

@ivar workers: the workers which represent the threads within the pool -
    the workers other than the coordinator.
@type workers: L{list} of 2-tuple of (L{IWorker}, C{workPerformer}) where
    C{workPerformer} is a 0-argument callable like C{performCoordination}.

@ivar threadpool: a modified L{threadpool.ThreadPool} to test.
@type threadpool: L{MemoryPool}
c                ó„   a € \        4       w  pS n        . S n        V 3R lp\        WAP                  V.VO5/ VB S n        R# )zÓ
Create a L{PoolHelper}.

@param testCase: a test case attached to this helper.

@type args: The arguments passed to a L{threadpool.ThreadPool}.

@type kwargs: The arguments passed to a L{threadpool.ThreadPool}
c                  ó~   <€ S P                   P                  \        4       4       S P                   R,          ^ ,          # )rÑ   rÒ   )rç   r   r   r    s   €r   r  Ú&PoolHelper.__init__.<locals>.newWorker‘  s-   ø€ Ø�L‰L×ÑÔ 2Ó 4Ô5Ø—<‘< Õ# AÕ&Ð&r   N)r   ÚperformCoordinationrç   r
  r5   r   )r   ÚtestCaser  r  r  r  s   f&*,  r   r   ÚPoolHelper.__init__„  sI   ø€ ô 1CÓ0DÑ-ˆ�TÔ-ØˆŒõ	'ô %ØŸ™¨	ð
Ø48ò
Ø<Bñ
ˆŽr   c                ó6   € V P                  4       '       d   K  R# )zq
Perform all currently scheduled "coordination", which is the work
involved in delegating work to other threads.
N)r)  r    s   &r   ÚperformAllCoordinationÚ!PoolHelper.performAllCoordination™  s   € ð
 ×&Ñ&×(Ò(Ùñ )r   )r)  r   rç   N)	r#   r$   r%   r&   r÷   r   r-  r(   r)   r*   s   @r   r%  r%  r  s   ø‡ € ñò"
÷*ð r   r%  c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )ÚMemoryBackedTestsi¢  zb
Tests using L{PoolHelper} to deterministically test properties of the
threadpool implementation.
c                óv  € \        V ^ ^
4      p^p\        V4       F  pVP                  P                  R 4       K!  	  VP	                  4        V P                  VP                  . 4       VP                  P                  4        VP	                  4        V P                  \        VP                  4      V4       R# )z¢
If a threadpool is told to do work before starting, then upon starting
up, it will start enough workers to handle all of the enqueued work
that it's been given.
c                  ó   € R # r   r/   r/   r   r   r�   Ú;MemoryBackedTests.test_workBeforeStarting.<locals>.<lambda>±  ó   € ±4r   N)	r%  r4   r   rZ   r-  r<   rç   rD   r   ©r   ÚhelperÚnÚxs   &   r   Útest_workBeforeStartingÚ)MemoryBackedTests.test_workBeforeStarting¨  s�   € ô ˜D ! RÓ(ˆØˆÜ�q–ˆAØ×Ñ×*Ñ*©<Ö8ñ à×%Ñ%Ô'Ø×Ñ˜Ÿ™¨Ô,Ø×Ñ×ÑÔ!Ø×%Ñ%Ô'Ø×Ñœ˜VŸ^™^Ó,¨aÖ0r   c                óž  € \        V ^ ^
4      p^2p\        V4       F  pVP                  P                  R 4       K!  	  VP	                  4        V P                  VP                  . 4       VP                  P                  4        VP	                  4        V P                  \        VP                  4      VP                  P                  4       R# )z�
If the amount of work before starting exceeds the maximum number of
threads allowed to the threadpool, only the maximum count will be
started.
c                  ó   € R # r   r/   r/   r   r   r�   ÚBMemoryBackedTests.test_tooMuchWorkBeforeStarting.<locals>.<lambda>Á  r4  r   N)
r%  r4   r   rZ   r-  r<   rç   rD   r   r>   r5  s   &   r   Útest_tooMuchWorkBeforeStartingÚ0MemoryBackedTests.test_tooMuchWorkBeforeStarting¸  sœ   € ô ˜D ! RÓ(ˆØˆÜ�q–ˆAØ×Ñ×*Ñ*©<Ö8ñ à×%Ñ%Ô'Ø×Ñ˜Ÿ™¨Ô,Ø×Ñ×ÑÔ!Ø×%Ñ%Ô'Ø×Ñœ˜VŸ^™^Ó,¨f×.?Ñ.?×.CÑ.CÖDr   r/   N)	r#   r$   r%   r&   r÷   r9  r>  r(   r)   r*   s   @r   r0  r0  ¢  s   ø‡ € ñò
1÷ Eð Er   r0  )r÷   r^   r   r   r   rX   Útwisted._threadsr   r   Útwisted.pythonr   r   r   r   Útwisted.trialr   r
   ÚsynchronizeÚSynchronousTestCaser-   rù   r;   r
  r%  r0  r/   r   r   Ú<module>rE     sž   ðñó
 
Û Û Û Û ç 5ß CÓ CÝ "÷!ñ !ðH × Ò �Ô 'ôH1�h×2Ñ2ô H1ôV-S˜×5Ñ5ô -Sô`9�×&Ñ&ô 9÷x-ñ -ô`$E˜×4Ñ4ö $Er   