��c@s�ddlmZddlZddlZddlZddlZddlZddlZd�Zd�Z ej
dkr�dZndZd�Zd �Z
d
�Zd�Zej
dkr�eZeZnd
�ZdS(i�(t_NcCs�y)ttjd��}|dkr(|SWnttfk
rBnXy'ttjd�}|dkri|SWnttfk
r�nXdS(s-try to count the number of CPUs on the systemtSC_NPROCESSORS_ONLNitNUMBER_OF_PROCESSORSi(tinttostsysconftAttributeErrort
ValueErrortenvirontKeyError(tn((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt countcpusscCs}|jdd�}|rdy t|�}|dkr7|SWqdtk
r`tjtd���qdXnttt�d�d�S(Ntworkertnumcpusis!number of cpus must be an integerii ( tconfigRRtutiltAbortRtmintmaxR(tuitsR
((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt_numworkers s
tposixgz��?g錠9Y>)FcCs6||}t|�}|t|||}|dkS(setry to determine whether the benefit of multiple processes can
outweigh the cost of starting themg333333�(Rt_startupcost(Rt costperoptnopstlineartworkerstbenefit((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt
worthwhile0s
cCs<t||t|��r+t||||�S|||f�S(sFrun a function, possibly in parallel in multiple worker
processes.
returns a progress iterator
costperarg - cost of a single task
func - function to run
staticargs - arguments to pass to every invocation of the function
args - arguments to split into chunks, to pass to individual
workers
(Rtlent_platformworker(Rt
costperargtfunct
staticargstargs((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyR8sc#s8tj�\}}t|�}tjtj��tjtjtj�gdg��x�||�D]�tj�}|dkr<tjtj��y\tj |�x;|||f�D]&\} }
tj
|d| |
f�q�Wtjd�Wq<tk
rtjd�q<z|j
�Wdtjd�Xq<Xn�j|�qfW�j�tj |�tj|dd�}�fd�����fd�}tjd|���j����fd�}
yDx=|D]5}|jd d
�}t|d�|d
d fVq�WWn��|
��nX|
�dS(Nis%d %s
i�trbcsZxS�D]K}ytj|tj�Wqtk
rQ}|jtjkrR�qRqXqWdS(N(RtkilltsignaltSIGTERMtOSErrorterrnotESRCH(tpterr(tpids(s4/sys/lib/python2.7/site-packages/mercurial/worker.pytkillworkerses
csLxE�D]=}ttj�d�}|r�r|�d<��qqWdS(Nii(t_exitstatusRtwait(Rtst(R.R-tproblem(s4/sys/lib/python2.7/site-packages/mercurial/worker.pytwaitforworkersms
ttargetcsgtjtj���j��d}|rc|dkrStjtj�|�ntj|�ndS(Ni(R&tSIGINTtjoinRR%tgetpidtsystexit(tstatus(t
oldhandlerR2tt(s4/sys/lib/python2.7/site-packages/mercurial/worker.pytcleanupus
t ii�(RtpipeRR&t getsignalR5tSIG_IGNt partitiontforktclosetwritet_exittKeyboardInterruptt tracebacktappendtreversetfdopent threadingtThreadtstarttsplitR(RR!R"R#trfdtwfdRtpargstpidtititemtfpR3R=tlinetl((R.R;R-R2R<s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt_posixworkerKsL
%cCs=tj|�rtj|�Stj|�r9tj|�SdS(s�convert a posix exit status into the same form returned by
os.spawnv
returns None if the process was stopped instead of exitingN(Rt WIFEXITEDtWEXITSTATUStWIFSIGNALEDtWTERMSIG(tcode((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt_posixexitstatus�s
tntccs{t|�}||||}}d}xMt|�D]?}|}||}|rg|d7}|d8}n|||!Vq4WdS(s,partition a list into N slices of equal sizeiiN(Rtxrange(tlsttnslicesR
tchunktsloptendRTRN((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyRB�s
(ti18nRR)RR&R8RLRRRtnameRRRRYR_RR/RB(((s4/sys/lib/python2.7/site-packages/mercurial/worker.pyt<module>sH <
|