ó  çƒQc@s×ddlmZddlZddlZddlZddlZddlZddlZd„Zd„Z ej dkr‚dZ ndZ d„Z d „Z d „Zd „Zej d krÊ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 countcpus s  cCs}|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áz„?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.pyR 8sc#s8tjƒ\}}t|ƒ}tjtjƒ‰tjtjtjƒgdg‰‰xôt||ƒD]ã}tjƒ}|dkr<tjtjˆƒy\tj |ƒx;|||fŒD]&\} } tj |d| | fƒq»Wtj dƒWq<t k rtj dƒq<z|j ƒWdtj dƒ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.pyt killworkerses  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 WIFEXITEDt WEXITSTATUSt WIFSIGNALEDtWTERMSIG(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&R8RLRR RtnameRRR RYR_RR/RB(((s4/sys/lib/python2.7/site-packages/mercurial/worker.pytsH      <