ó
    6°hÒ=  ã                  ó   • S SK Jr  S SKrS SKrS SK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JrJr  \	R"                  " SS\SS	9  S
 rS rS r\R,                  (       a  \R.                  S:w  d  \R0                  (       a  Sr\R0                  rOSrSrSS jr   SS jrSS jrS rSS jr\R0                  (       a  \r O\r \r!S r"g)é    )ÚannotationsNé   )Ú_)ÚencodingÚerrorÚpycompatÚscmutilÚignorez_This process \(pid=\d+\) is multi-threaded, use of fork\(\) may lead to deadlocks in the child.zmercurial.worker)ÚmessageÚcategoryÚmodulec                 óú   •  [        [        R                  " S5      5      n U S:”  a  U $   [        [
        R                  S   5      n U S:”  a  U $  g! [        [        4 a     N9f = f! [        [        4 a     gf = f)z-try to count the number of CPUs on the systemÚSC_NPROCESSORS_ONLNr   s   NUMBER_OF_PROCESSORSr   )ÚintÚosÚsysconfÚAttributeErrorÚ
ValueErrorr   ÚenvironÚKeyError)Úns    Ú2/usr/lib/python3/dist-packages/mercurial/worker.pyÚ	countcpusr   (   s‘   € ðÜ”—
’
Ð0Ó1Ó2ˆØˆq‹5ØˆHð ðÜ”× Ñ Ð!8Ñ9Ó:ˆØˆq‹5ØˆHð ð
 øô œJÐ'ó Ùðûô ”jÐ!ó Øàðús"   ‚&A «#A' ÁA$Á#A$Á'A:Á9A:c                óô   • U R                  SS5      nU(       a   [        U5      nUS:¼  a  U$  [        [        [        5       S5      S5      $ ! [         a     [        R                  " [        S5      5      ef = f)Nó   workers   numcpusr   s!   number of cpus must be an integeré   é    )	Úconfigr   r   r   ÚAbortr   ÚminÚmaxr   )ÚuiÚsr   s      r   Ú_numworkersr$   >   su   € Ø
�	‰	�)˜ZÓ(€AÞð	GÜ�A“ˆAØ�A‹vØ�ð ô Œs”9“; Ó" BÓ'Ð'øô ó 	GÜ—+’+œaÐ DÓEÓFÐFð	Gús   ›A Á*A7c                 óX   • [         R                  " 5       [         R                  " 5       :H  $ ©N)Ú	threadingÚcurrent_threadÚmain_thread© ó    r   Úismainthreadr,   J   s   € Ü×#Ò#Ó%¬×)>Ò)>Ó)@Ñ@Ð@r+   s   OpenVMSg{®Gáz„?gêŒ 9Y>)FFc                ór   • U(       d  [         (       a  gX-  n[        U 5      nU[        U-  XE-  -   -
  nUS:¬  $ )zatry to determine whether the benefit of multiple processes can
outweigh the cost of starting themFg333333Ã?)Ú_DISALLOW_THREAD_UNSAFEr$   Ú_STARTUP_COST)r"   Ú	costperopÚnopsÚ
threadsafeÚlinearÚworkersÚbenefits          r   Ú
worthwhiler6   [   sB   € ö ×1Ò1ØàÑ€FÜ˜"‹o€GØœ¨Ñ/°&Ñ2BÑBÑC€GØ�d‰?Ðr+   c           	     óÖ   • U R                  SS5      nU(       a  [        [        L a  [        5       (       d  SnU(       a$  [	        X[        U5      US9(       a  [        XX4XWS9$ U" X44-   6 $ )aÌ  run a function, possibly in parallel in multiple worker
processes.

returns a progress iterator

costperarg - cost of a single task

func - function to run. It is expected to return a progress iterator.

staticargs - arguments to pass to every invocation of the function

args - arguments to split into chunks, to pass to individual
workers

hasretval - when True, func and the current function return an progress
iterator then a dict (encoded as an iterator that yield many (False, ..)
then a (True, dict)). The dicts are joined in some arbitrary order, so
overlapping keys are a bad idea.

threadsafe - whether work items are thread safe and can be executed using
a thread-based worker. Should be disabled for CPU heavy tasks that don't
release the GIL.

prefork - a parameterless Callable that is invoked prior to forking the
process.  fork() is only used on non-Windows platforms, but is also not
called on POSIX platforms if the work amount doesn't warrant a worker.
r   s   enabledF)r2   )Úprefork)Ú
configboolÚ_platformworkerÚ_posixworkerr,   r6   Úlen)	r"   Ú
costperargÚfuncÚ
staticargsÚargsÚ	hasretvalr2   r8   Úenableds	            r   ÚworkerrC   h   sd   € ðJ �m‰m˜I zÓ2€GÞ”?¤lÒ2¼<¿>¹>ð ˆæ”:˜b¬c°$«iÀJ×OÜØ�j¨	ñ
ð 	
ñ �˜gÑ%Ð&Ð&r+   c           	   #  ó²	  ^^^^^^^^^^^^^ ^!#   • [        U 5      n[        R                  " [        R                  5      m[        R                  " [        R                  [        R                  5        [        5       S/smmUU4S jmSUU4S jjm UUU 4S jn[        R                  " [        R                  U5      mU R                  5         [        R                  " 5       n/ m0 n	U(       a  U" 5         [        U[        U[        U5      5      5       GH  m[        R                  " 5       u  mm!TR                  TT!45        Sn
 [        R                  " 5       nUS:X  ak  [        R                  " [        R                  T5        [        R                  " [        R                  T5        UUUUUU!4S jn[         R"                  " X5      n
[        R                  " 5       U:w  a+   U R                  5         [        R.                  " U
S	-  5        O TR1                  W5        GM     [2        R4                  " 5       mT HR  u  mm![        R6                  " T!5        TR9                  [        R:                  " TS
S5      [2        R<                  5        MT     S mU4S jnUUUUU 4S jn [        T5      nUS:”  ag  TR?                  5        HK  u  nn U" UR@                  5       H.  nU(       a   US   (       a  U	RC                  US   5        M*  Uv •  M0     MM     US:”  a  Mg  U" 5       nU(       aG  US:  a+  [        RH                  " [        R                  " 5       U* 5        [J        RL                  " U5      eU(       a  SU	4v •  g g !   [        R                  " 5       U:X  a  e [$        R&                  " 5       S   n[)        U[*        5      (       + nU R-                  US9   GN= f!    GNñ= f! [        R.                  " U
S	-  5        f = f! [        R                  " 5       U:w  aQ   U R                  5         O!    O= f[        R.                  " U
S	-  5        f ! [        R.                  " U
S	-  5        f = ff = f! [D         a?    TRG                  UR@                  5        UR@                  R7                  5         US-  n GMö  f = f!   T" 5         U" 5         e = f7f)Nr   c                 óÐ   >• [         R                   " [         R                  T5        T H)  n  [        R                  " U [         R                  5        M+     g ! [
         a     M;  f = fr&   )ÚsignalÚSIGCHLDr   ÚkillÚSIGTERMÚProcessLookupError)ÚpÚoldchldhandlerÚpidss    €€r   ÚkillworkersÚ!_posixworker.<locals>.killworkers    sL   ø€ ô 	�Š”f—n‘n nÔ5ãˆAðÜ—’˜œ6Ÿ>™>Ö*ò øô &ó Úðús   ­%AÁ
A%Á$A%Tc                óZ  >• TR                  5        Hu  nS=p# [        R                  " X(       a  SO[        R                  5      u  p#U(       d  M?  TR                  U5        [        U5      nU(       d  Md  TS   (       a  Mp  UTS'   Mw     g ! [         a    TR                  U5         Naf = f©Nr   )Úcopyr   ÚwaitpidÚWNOHANGÚChildProcessErrorÚdiscardÚ_exitstatus)ÚblockingÚpidrK   ÚstrM   Úproblems       €€r   ÚwaitforworkersÚ$_posixworker.<locals>.waitforworkers¬   sŒ   ø€ Ø—9‘9–;ˆCØˆJˆAð"ÜŸ
š
 3­h©¼B¿J¹JÓH‘�ö
 ñ Ø�L‰L˜ŒOÜ˜R“ˆBßˆr˜' !Ÿ*™*Ø�˜“
ò øô %ó "ð —‘˜SÖ!ð"ús   ™/BÂB*Â)B*c                ó6   >• T" SS9  TS   (       a  T" 5         g g )NF)rX   r   r*   )ÚsignumÚframerN   r[   r\   s     €€€r   ÚsigchldhandlerÚ$_posixworker.<locals>.sigchldhandler¾   s   ø€ Ù Ò&Ø�1�:Ù�Mð r+   éÿÿÿÿc                 ót  >• TS S  H1  u  p[         R                  " U 5        [         R                  " U5        M3     [         R                  " T5        [         R                  " T	S5       nT" TT4-   6  H)  n[        R                  " X25        UR                  5         M+     S S S 5        g! , (       d  f       g= f)Nrc   Úwbr   )r   ÚcloseÚfdopenÚpickleÚdumpÚflush)
ÚrÚwÚwfÚresultr>   ÚpargsÚpipesÚrfdr?   Úwfds
       €€€€€€r   Ú
workerfuncÚ _posixworker.<locals>.workerfuncâ   sŒ   ø€ Ø % c r£
™˜ÜŸš œÜŸš žñ !+ô —H’H˜S”MÜŸš 3¨Ô-°Ù&*¨Z¸5¸(Ñ-BÓ&D˜FÜ"ŸKšK¨Ô3ØŸH™HžJñ 'E÷ .ð ÷	 .Ô-ð ús   Á)7B)Â)
B7)Úforceéÿ   Úrbi   c                óº   • [         R                  " U R                  5       S5        U R                  5       n[         R                  " U R                  5       S5        U$ ©NFT)r   Úset_blockingÚfilenoÚpeek)ÚfÚress     r   Úpeek_nonblockÚ#_posixworker.<locals>.peek_nonblock  s:   € Ü
�Š˜Ÿ™›
 EÔ*Ø�f‰f‹hˆÜ
�Š˜Ÿ™›
 DÔ)Øˆ
r+   c              3  óÈ   >#   • [         R                  " U 5      v •  [        T" U 5      5      S:”  a0  [         R                  " U 5      v •  [        T" U 5      5      S:”  a  M/  g g 7frQ   )rh   Úloadr<   )r}   r   s    €r   Úload_allÚ_posixworker.<locals>.load_all  sJ   øé € ô �kŠk˜!‹nÒÜ‘- Ó"Ó# aÓ'Ü—+’+˜a“.Ò ô ‘- Ó"Ó# a×'ùs   ƒAA"Á A"c                 óÐ   >• [         R                   " [         R                  T5        T" 5         [         R                   " [         R                  T 5        TR                  5         TS   $ rQ   )rF   ÚSIGINTrG   rf   )rL   Ú
oldhandlerr[   Úselectorr\   s   €€€€€r   ÚcleanupÚ_posixworker.<locals>.cleanup  sA   ø€ Ü�Š”f—m‘m ZÔ0ÙÔÜ�Š”f—n‘n nÔ5Ø�‰ÔØ�q‰zÐr+   r   ©T)'r$   rF   Ú	getsignalr†   ÚSIG_IGNÚsetrG   rj   r   ÚgetpidÚ	partitionr    r<   ÚpipeÚappendÚforkr	   Ú	callcatchÚsysÚexc_infoÚ
issubclassÚKeyboardInterruptÚ	tracebackÚ_exitÚaddÚ	selectorsÚDefaultSelectorrf   Úregisterrg   Ú
EVENT_READÚselectÚfileobjÚupdateÚEOFErrorÚ
unregisterrH   r   ÚWorkerError)"r"   r>   r?   r@   rA   r8   r4   ra   Ú	parentpidÚretvalÚretrY   rs   Úexctyperu   rƒ   r‰   Ú	openpipesÚkeyÚeventsr~   ÚstatusrN   rL   r‡   ro   r   rM   rp   r[   rq   rˆ   r\   rr   s"    ``                   @@@@@@@@@@@@r   r;   r;   š   s�  ÿýé € Ü˜"‹o€GÜ×!Ò!¤&§-¡-Ó0€JÜ
‡M‚M”&—-‘-¤§¡Ô0Ü“E˜A˜3€M€Dˆ'ö
÷ ð  ÷$ô
 —]’]¤6§>¡>°>ÓB€NØ‡H�H„JÜ—	’	“€IØ€EØ€FæÙŒ	ä˜4¤ W¬c°$«iÓ!8×9ˆô —7’7“9‰ˆˆSØ�‰�c˜3�ZÔ ð ˆð	(Ü—'’'“)ˆCØ�a‹xÜ—’œfŸm™m¨ZÔ8Ü—’œfŸn™n¨nÔ=÷	ò 	ô ×'Ò'¨Ó7�ô �yŠy‹{˜iÓ'ð(Ø—H‘H”Jô —H’H˜S 3™YÕ'ð (ð 	�‰��ña :ôb ×(Ò(Ó*€HÛ‰ˆˆSÜ
�Š�Œð
 	×Ñœ"Ÿ)š) C¨¨tÓ4´i×6JÑ6JÖKñ òõ!÷ñ ðÜ˜“Jˆ	Ø˜!‹mØ'Ÿ™Ö0‘��Vð#Ù'¨¯©Ö4˜Þ$¨¨Q¯Ø"ŸM™M¨#¨a©&Ö1à"%œIó	  5ñ  1ð ˜!�mñ$ ‹Y€FÞØ�A‹:Ü�GŠG”B—I’I“K & Ô)Ü×Ò Ó'Ð'ÞØ�FˆlÓð øðO	&Ü�yŠy‹{˜iÓ'ØÜ—l’l“n QÑ'ˆGÜ" 7Ô,=Ó>Ô>ˆEØ�L‰L˜uˆLÔ%ûð
Úûä—H’H˜S 3™YÕ'ûô �yŠy‹{˜iÓ'ð(Ø—H‘H•JøðÙúä—H’H˜S 3™YÕ'ø”B—H’H˜S 3™YÕ'úð (ûôb  ó #Ø×'Ñ'¨¯©Ô4à—K‘K×%Ñ%Ô'à ‘N”Ið#ûðÙŒÙŒ	Øüsº   �D5SÅBNÇSÇ&O"Ç6B1SÊ('S ËAQ7Ì
S Ì A$SÎAOÏPÏ"O'Ï$O*Ï*PÐSÐQ4Ð#P4Ð3QÐ4P8	Ð6QÐ;Q4ÑQ0	Ñ0Q4Ñ4SÑ7AS Ò;S Ò?S Ó S ÓSÓSc                óÊ   • [         R                  " U 5      (       a  [         R                  " U 5      $ [         R                  " U 5      (       a  [         R                  " U 5      * $ g)z€convert a posix exit status into the same form returned by
os.spawnv

returns None if the process was stopped instead of exitingN)r   Ú	WIFEXITEDÚWEXITSTATUSÚWIFSIGNALEDÚWTERMSIG)Úcodes    r   Ú_posixexitstatusr´   9  sH   € ô
 
‡|‚|�D×ÑÜ�~Š~˜dÓ#Ð#Ü	�Š˜×	Ñ	Ü—’˜TÓ"Ð#Ð#ð 
r+   c              #  óÂ  ^ ^#   •  " S S[         R                  5      n/ mUU 4S jn[        T 5      n[        R                  R                  5       n	[        R                  R                  5       n
0 n[        X8S-  5       H  nU
R                  U5        M     [        U5       H-  nU" X©X5      nTR                  U5        UR                  5         M/      [        T5      S:”  aç  U	R                  5       (       dQ  U	R                  5       nU(       a  US   (       a  UR                  US   5        OUv •  U	R                  5       (       d  MQ  TS   R                  S5        T Vs/ s H  nUR!                  5       (       a  M  UPM     nnU H-  nUR"                  b  UR"                  eTR%                  U5        M/     [        T5      S:”  a  Mç  U	R                  5       (       dQ  U	R                  5       nU(       a  US   (       a  UR                  US   5        OUv •  U	R                  5       (       d  MQ  U(       a  SU4v •  g g s  snf ! [&        [(        4 a	    U" 5         e f = f7f)	Nc                  ó&   • \ rS rSrS rS rS rSrg)Ú_windowsworker.<locals>.WorkeriE  c                ó¦   • [         R                  R                  " U /UQ70 UD6  Xl        X l        X0l        X@l        SU l        SU l        S U l	        g ry   )
r'   ÚThreadÚ__init__Ú
_taskqueueÚ_resultqueueÚ_funcÚ_staticargsÚ_interruptedÚdaemonÚ	exception)ÚselfÚ	taskqueueÚresultqueuer>   r?   r@   Úkwargss          r   rº   Ú'_windowsworker.<locals>.Worker.__init__F  sN   € ô ×Ñ×%Ò% dÐ<¨TÒ<°VÒ<Ø'ŒOØ +ÔØŒJØ)ÔØ %ˆDÔØˆDŒKØ!ˆD�Nr+   c                ó   • SU l         g )NT)r¿   )rÂ   s    r   Ú	interruptÚ(_windowsworker.<locals>.Worker.interruptR  s
   € Ø $ˆDÕr+   c                óÜ  •  U R                   R                  5       (       d�   U R                   R                  5       nU R                  " U R                  U4-   6  H1  nU R
                  R                  U5        U R                  (       d  M1    g    U R                   R                  5       (       d  MŽ  g g ! [        R                  R                   a     g f = f! [         a  nX0l        e S nAff = fr&   )r»   ÚemptyÚ
get_nowaitr½   r¾   r¼   Úputr¿   r   ÚqueueÚEmptyÚ	ExceptionrÁ   )rÂ   r@   r~   Úes       r   ÚrunÚ"_windowsworker.<locals>.Worker.runU  sÃ   € ðØŸ/™/×/Ñ/×1Ñ1ð
Ø#Ÿ™×9Ñ9Ó;˜Ø#'§:¢:¨t×/?Ñ/?À4À'Ñ/IÓ#J˜CØ ×-Ñ-×1Ñ1°#Ô6ð  $×0×0Ñ0Ù &ñ $Kð Ÿ/™/×/Ñ/×1Õ1øô $Ÿ>™>×/Ñ/ó Ùðûäó ð "#”Øûð	úsG   ‚C ¢A$B1 Â
B1 ÂB1 ÂC Â1CÃC ÃCÃC Ã
C+ÃC&Ã&C+)r½   r¿   r¼   r¾   r»   rÀ   rÁ   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__rº   rÈ   rÒ   Ú__static_attributes__r*   r+   r   ÚWorkerr·   E  s   † ò
	"ò	%õ	r+   rÙ   c                 ó.  >• [         R                   " 5       S-   n T H  nUR                  5         M     T H]  nU [         R                   " 5       -
  nUR                  U5        UR                  5       (       d  MC  TR	                  [        S5      5          g    g )Nr   s:   failed to kill worker threads while handling an exception
)ÚtimerÈ   ÚjoinÚis_aliveÚwarnr   )Ú
cleanupendÚtÚremainingtimeÚthreadsr"   s      €€r   ÚtrykillworkersÚ&_windowsworker.<locals>.trykillworkersk  sv   ø€ ä—Y’Y“[ 1‘_ˆ
ÛˆAØ�K‰KŽMñ ãˆAØ&¬¯ª«Ñ4ˆMØ�F‰F�=Ô!Ø�z‰z�|‹|ð
 —‘Üð3óôñ ò r+   é   r   r   gš™™™™™©?T)r'   r¹   r$   r   rÎ   ÚQueuer�   rÍ   Úranger’   Ústartr<   rË   Úgetr¢   rÜ   rÝ   rÁ   ÚremoverÐ   r˜   )r"   r>   r?   r@   rA   r8   rÙ   rã   r4   rÄ   rÃ   r§   ro   Ú_irà   r~   Ú_tÚfinishedthreadsrâ   s   `                 @r   Ú_windowsworkerrî   D  sï  ùé € ô"”×!Ñ!ô "ðH €Göô* ˜"‹o€GÜ—.‘.×&Ñ&Ó(€KÜ—‘×$Ñ$Ó&€IØ€Fô ˜4¨2¡Ö.ˆØ�‰�eÖñ /ä�GŽnˆÙ�9¨4Ó<ˆØ�‰�qÔØ	�‰Ž	ñ ðÜ�'‹l˜QÓØ!×'Ñ'×)Ñ)Ø!—o‘oÓ'�Þ  Q§Ø—M‘M # a¡&Õ)à’Ið "×'Ñ'×)Ó)ð �A‰J�O‰O˜DÔ!Ù,3ÓIªG b¸2¿;¹;¿=Ÿr©GˆOÐIÛ$�Ø—;‘;Ñ*ØŸ+™+Ð%Ø—‘˜qÖ!ñ %ô �'‹l˜QÕð  ×Ñ×!Ñ!Ø�o‰oÓˆÞ˜˜QŸØ�M‰M˜#˜a™&Õ!àŠIð ×Ñ×!Ó!ö Ø�FˆlÓð ùò Jøô
 Ô(Ð)ó ÙÔØðüsE   „CIÃA3I ÅI Å H>Å=H>ÆAI Ç	A$IÈ/IÈ>I ÉIÉIc              #  óB   #   • [        U5       H  nXSU2   v •  M     g7f)aŽ  partition a list into N slices of roughly equal size

The current strategy takes every Nth element from the input. If
we ever write workers that need to preserve grouping in input
we should consider allowing callers to specify a partition strategy.

olivia is not a fan of this partitioning strategy when files are involved.
In his words:

    Single-threaded Mercurial makes a point of creating and visiting
    files in a fixed order (alphabetical). When creating files in order,
    a typical filesystem is likely to allocate them on nearby regions on
    disk. Thus, when revisiting in the same order, locality is maximized
    and various forms of OS and disk-level caching and read-ahead get a
    chance to work.

    This effect can be quite significant on spinning disks. I discovered it
    circa Mercurial v0.4 when revlogs were named by hashes of filenames.
    Tarring a repo and copying it to another disk effectively randomized
    the revlog ordering on disk by sorting the revlogs by hash and suddenly
    performance of my kernel checkout benchmark dropped by ~10x because the
    "working set" of sectors visited no longer fit in the drive's cache and
    the workload switched from streaming to random I/O.

    What we should really be doing is have workers read filenames from a
    ordered queue. This preserves locality and also keeps any worker from
    getting more than one file out of balance.
N)rç   )ÚlstÚnslicesÚis      r   r�   r�   ®  s#   é € ô: �7Ž^ˆØ�*�W�*‰oÔò ùs   ‚r‹   )FTNr&   )#Ú
__future__r   r   rh   rœ   rF   r•   r'   rÛ   ÚwarningsÚi18nr   Ú r   r   r   r	   ÚfilterwarningsÚDeprecationWarningr   r$   r,   ÚisposixÚsysplatformÚ	iswindowsr/   r.   r6   rC   r;   r´   rî   r:   rW   r�   r*   r+   r   Ú<module>rü      sç   ðõ #ã 	Û Û Û Û 
Û Û Û å ÷ó ð 	× Ò Øð	@ð  Øòòò,	(òAð
 ××˜×-Ñ-°Ó;Ø××Ø€Mð '×0Ñ0Ñà€MØ#Ðô
ð& ØØô/'ôd\ò~$ô`ðF ××Ø$�Oà"€OØ"€Kór+   