mò N ¤Ec@sQdZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dk Z dZ dZ edjo›hZeiZeiZeiƒZee_ee_eieeiƒƒdƒeiƒx;eiiƒZeieƒpáeidƒeiƒeeiiƒƒZ eii!e ƒZ"e i#e"ƒ\Z$Z%Z&gZ'e%D]Z(e'e)e(dd ƒqY['Z*xGe&D]?Z+ye,e+ƒe-ƒe+e*D]6Z1ye2e1ƒWq=d GHei.ei/ƒŒq=Xq=We-ƒe$Z3ye3e0ŒZ4Wn%d GHei.ei/ƒŒdZ4nXe i6e4ei7ƒfƒZ"eiee8e"ƒƒdƒeie"ƒeiƒqÙWndfd„ƒYZ9dfd„ƒYZ:dfd„ƒYZ;dS(sfParallel Python SMP http://www.parallelpython.com - documentation, usage examples and support forum Ns>Copyright (c) 2005-2007 Vitalii Vanovschi. All rights reserveds1.1 betat__main__s isY stexecs-An error has occured during the module importsN s/An error has occured during the function imports2An error has occured during the function executiont_TaskcBstZd„Zd„ZRS(NcCs)tiƒ|_|iiƒ||_dS(N(tthreadt allocate_locktselftlocktacquirettid(RtserverR((t/home/vitaly/dev/ppsmp/ppsmp.pyt__init__Fs cCs!|iiƒ|iiƒ|iS(N(RRRtreleasetresult(R((R t__call__Ks  (t__name__t __module__R R(((R REs t_WorkercBstZd„ZRS(NcCs~dtidtd}tiidƒod|d}nti|ƒ\|_|_ t |ii ƒƒ|_ t |_dS(Ns"s" "twin(tsyst executablet__file__tcommandtplatformt startswithtpopen2RtrtwtinttreadlinetpidtTruetis_free(RR((R R Rs (RRR (((R RQstServercBs’tZdZdeieid„Zd„Zd„Z d„Z ffd„Z d„Z dd„Z d „Zd „Zd „Zd „Zd „ZRS(s/Parallel Python SMP execution server class t autodetectcCsš|i||ƒtidt|ƒƒd|_g|_d|_ t i ƒ|_ t i ƒ|_ g|_h|_|i|ƒtid|ifƒdS(sè Creates server instance ncpus - the number of worker processes, if parammeter is omitted it will be set to the number of processors in the system loglevel - logging level logstream - log destiunation With ncpus = 1 all tasks are executed consequently For the best performance either use default "autodetect" value or set ncpus to the total number of processors in the system screating server instance is$ppsmp server started with %d workersN(Rt_Server__initLogtloglevelt logstreamtloggingtdebugtstrt _Server__tidt_Server__queuet_Server__activeTasksRRt_Server__addToActiveTasks_lockt_Server__scheduler_lockt_Server__workerst_Server__sourcesHMt set_ncpustncpustinfot_Server__ncpus(RR1R$R%((R R `s       cCs¡tidt|ƒƒxƒ|iD]x}tid|ifƒtii dƒo"t i dt|iƒdƒq!t i |idƒt i |idƒq!WdS(Nsdeleting server instance s#exiting worker process with pid=%d RsTASKKILL /PID s /Fi i(R&R'R(RR.tworkerRRRRtostpopentkilltwaitpid(RR4((R t__del__xs "cCs‹ttdƒo8tidƒ}t|tƒo|djo|SqHntiidƒo,ttidƒ}|djo|Sq‡ndS(NtsysconftSC_NPROCESSORS_ONLNitNUMBER_OF_PROCESSORSi(thasattrR5R:R1t isinstanceRtenvironthas_key(RR1((R t__detect_ncpus„s   cCshti|ƒ}|i|ƒ|itidƒƒtidƒ|_ |i i |ƒ|i i|ƒdS(Ns%%(asctime)s %(levelname)s %(message)st( R&t StreamHandlerR%t logHandlertsetLevelR$t setFormattert Formattert getLoggerRt_Server__loggert addHandler(RR$R%RD((R t __initLog’s  cCse|iƒ}t||ƒ}|ii|||||fƒ|i i d||i fƒ|iƒ|S(sSubmits function to the execution queue func - function to be executed args - tuple with arguments of the 'func' depfuncs - tuple with functions which might be called from 'func' modules - tuple with module names to import sTask %i submited, function='%s'N(Rt_Server__gentidRRtjobR*tappendtfunctargstdepfuncstmodulesRIR't func_namet_Server__scheduler(RRORPRQRRRMR((R tsubmit›s  cCs|iS(s&Returns the number of worker processesN(RR3(R((R t get_ncpus«scCsÂ|djo|iƒ}nt|tƒptdƒ‚n|djotdƒ‚n|t|iƒjoE|ii g}t |t|iƒƒD]}|t ƒq—~ƒn||_dS(s¶Sets the number of worker processes ncpus - the number of worker processes, if parammeter is omitted it will be set to the number of processors in the systemR"sncpus must have 'int' typeis ncpus must be a positive integerN(R1Rt_Server__detect_ncpusR>Rt TypeErrort ValueErrortlenR.textendt_[1]trangetxRR3(RR1R\R^((R R0¯s  EcCsÈ|iiƒ|i|ijo—|io|iidƒ}x?|iD]}|i ot |_ PqFqFW|i i dƒd‚|idƒyti|i||fƒWq·q·Xn|iiƒdS(NisThere are no free workers leftsError: No free workersi(RR-RR+R3R*tpopttaskR.R4R tFalseRIterrort_Server__add_to_active_tasksRtstart_new_threadt _Server__runR (RR`R4((R t __scheduler½s       cCsDt|ƒ}|ii|ƒpti|ƒ|i|