当前位置: 首页>>代码示例>>Python>>正文


Python ThreadPool.joinAll方法代码示例

本文整理汇总了Python中ThreadPool.ThreadPool.joinAll方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.joinAll方法的具体用法?Python ThreadPool.joinAll怎么用?Python ThreadPool.joinAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadPool.ThreadPool的用法示例。


在下文中一共展示了ThreadPool.joinAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verifAllProxy

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import joinAll [as 别名]
    def verifAllProxy(self, pfile='Proxy.txt', out=None, threadnbr=15):
        '''Verification de tous les proxys du fichier (pfile).
        Peut enregistrer le Proxy verifier dans un fichier (out)
        Methode a amelioré. '''
        proxys = self.getProxysFromFile(pfile)
        
#        def killthread(thread, timeout=30):
#            """C'est pas beau !"""
#            time.sleep(timeout)
#            if thread.isAlive():
#                thread._Thread__stop()
                
        def verifT(prox):
            if prox.verif():
                self.goodproxy.append(prox)
            
            
        pool = ThreadPool(threadnbr)
        for prox in proxys:
            pool.queueTask(verifT, prox)
            
        timeout = (len(proxys) / threadnbr * 30 + 5) * 1.5
        print 'Temps max : %s' % timeout
        #time.sleep(timeout)
        #print 'arret'
        
        #print self.goodproxy
        
        #TOTO mieux
        count = 0
        while pool.getThreadCount()>0:
            time.sleep(1)
            count+=1
            if count>timeout:
                pool.joinAll(False, False)
            #print pool.getThreadCount()
        
        if out != None:
            with open(out, 'w') as pvfile:
                for Proxy in self.goodproxy:
                    print str(Proxy)
                    pvfile.write(str(Proxy) + '\n')
开发者ID:Demmat,项目名称:millenium-bot,代码行数:44,代码来源:HttpProxy.py

示例2: run_multi_integrate

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import joinAll [as 别名]
def run_multi_integrate(xpar_init,inp_f=None,main_directory=None,
                            nThreads=2,init=0):    
    from ThreadPool import ThreadPool
    # Copy 
    xpar = xpar_init.copy()
    global FinishedThread
    FinishedThread = 0
    pool = ThreadPool(nThreads)
    if init:
       xpar.JOB = "INIT","DEFPIX","INTEGRATE","CORRECT"
       files_to_copy = "XPARM.XDS","X-CORRECTIONS.pck","Y-CORRECTIONS.pck"
    else:
       xpar.JOB = "DEFPIX","INTEGRATE","CORRECT"
       files_to_copy = "XPARM.XDS","BKGINIT.pck","BLANK.pck",\
                       "GAIN.pck","X-CORRECTIONS.pck","Y-CORRECTIONS.pck"
    if not main_directory: main_directory = os.getcwd()
    if os.path.isdir(main_directory):
         os.chdir(main_directory)
    else:
         print "STOP! Directory not found:",directory
         sys.exit()
    range_list = new_range(xpar.DATA_RANGE, nThreads)

    _templ = xpar.NAME_TEMPLATE_OF_DATA_FRAMES
    if type(_templ) ==  type("") and _templ[0] != "/":
        xpar.NAME_TEMPLATE_OF_DATA_FRAMES = "../" + \
                   xpar.NAME_TEMPLATE_OF_DATA_FRAMES

    if type(_templ) == type(()) and _templ[0][0] != "/":
        xpar.NAME_TEMPLATE_OF_DATA_FRAMES = "../" + \
                   xpar.NAME_TEMPLATE_OF_DATA_FRAMES[0], \
                   xpar.NAME_TEMPLATE_OF_DATA_FRAMES[1]

    hklfiles = []
    startTime = time()
    print "\n"
    for NTh in range(nThreads):
        #newdir = os.path.join(main_directory,"integrate_batch_%d" % (NTh+1))
        newdir = "integrate_batch_%d" % (NTh+1)
        if not os.path.exists(newdir): os.mkdir(newdir)
        for file in files_to_copy:
            if os.path.isfile(file):
                shutil.copyfile(file,os.path.join(newdir,file))
            else:
                print "STOP: Can't find file",file
                sys.exit()
        os.chdir(newdir)
        xpar.DATA_RANGE = range_list[NTh]+1,range_list[NTh+1]
        xpar.SPOT_RANGE = (range_list[NTh]+1,range_list[NTh]+4),
        args = (xpar,inp_f,"xds.out",os.getcwd(),0)
        pool.queueTask(run_xds_thread,args,taskCallback)
        # To avoid chdir before the xds process is started...
        print "  ==>  Threads XDS started for integration of images %4d to %4d"\
                % (xpar.DATA_RANGE[0],xpar.DATA_RANGE[1])
        sleep(2.0)
        os.chdir("..")
        hklfiles.append(os.path.join(newdir,"XDS_ASCII.HKL"))
    pool.joinAll()
    print "\n"
    while FinishedThread != nThreads:
        sleep(0.1)
    #read cell
    endTime = time()
    print "\n    Integration time: %.1f seconds" % (endTime - startTime)
    H = read_xdsascii_head(hklfiles[0])
    if H["friedels_law"] == "TRUE": H["friedels_law"] = 1
    elif H["friedels_law"] == "FALSE": H["friedels_law"] = 0
    dmin = get_maxResolution(os.path.join(newdir,"INTEGRATE.LP"))
    xlatt = Lattice(H["cell"], "Unknown", symmetry=H["sym"],
                      dmin=dmin, friedels_law=H["friedels_law"])
    run_xscale(hklfiles, "batch_merge.hkl", xlatt, save=1, out_f="xscale.out")
开发者ID:RAPD,项目名称:RAPD,代码行数:73,代码来源:xupy.py


注:本文中的ThreadPool.ThreadPool.joinAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。