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


Python ThreadPool.add_job方法代码示例

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


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

示例1: test_server_list

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
    def test_server_list(cls, target_list, shared_settings):
        """
        Tests connectivity with each server of the target_list and returns
        the list of online servers.
        """

        # Use a thread pool to connect to each server
        thread_pool = ThreadPool()
        for target_str in target_list:
            thread_pool.add_job((cls._test_server, (target_str, shared_settings)))

        nb_threads = min(len(target_list), cls.MAX_THREADS)
        thread_pool.start(nb_threads)

        # Return valid targets
        for (job, target) in thread_pool.get_result():
            yield target

        # Use None as a sentinel
        yield None

        # Return invalid targets
        for (job, exception) in thread_pool.get_error():
            yield exception

        thread_pool.join()
        return
开发者ID:CRYPTOlab,项目名称:sslyze,代码行数:29,代码来源:ServersConnectivityTester.py

示例2: test_connectivity

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
    def test_connectivity(self,  timeout):
        """
        Tests connectivity with each server of the target_list and returns 
        the list of online servers.
        """
        
        # Use a thread pool to connect to each server
        thread_pool = ThreadPool()
        for target_str in self._target_list:
            thread_pool.add_job((self._test_server,
                                (target_str, timeout)))
            
        nb_threads = min(len(self._target_list), self.MAX_THREADS)
        thread_pool.start(nb_threads)
        
        # Recover valid targets
        for (job, target) in thread_pool.get_result():
            self._targets_OK.append(target)
            yield target
                        
        # Store invvalid targets
        for (job, exception) in thread_pool.get_error():
            self._targets_ERR.append(exception)

        thread_pool.join()
        return   
开发者ID:kirei,项目名称:sslyze,代码行数:28,代码来源:ServersConnectivityTester.py

示例3: test

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
def test():
	print('start testing')
	tp = ThreadPool()
	for i in range(15):
		time.sleep(0.1)
		tp.add_job(test_job, i)
	
	t = time.time()
	tp.wait_for_complete()
	
	print('s:'+str(time.time()-t))
	print('end testing')
开发者ID:WiGoy,项目名称:WeScored-V2.0,代码行数:14,代码来源:test.py

示例4: GetMatchPage

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
def GetMatchPage(season, league, matches):
	'''
	获取指定联赛的Match页面
	'''
	tp = ThreadPool()
	print('Start updating ' + season + ' ' + league + ' matches...')
	dirLeague = Global.Dir_Root + season + '\\' + league
	
	for matchID in sorted(matches.keys()):
		urlMatch = matches.get(matchID)
		tp.add_job(GetPageText, dirLeague, matchID, urlMatch, len(matches))
	
	tp.wait_for_complete()
	
	if len(matches) > 0:
		print('\n' + season + ' ' +league + ' updating complete!\n')
	else:
		print(season + ' ' + league + ' updating complete!\n')
开发者ID:WiGoy,项目名称:WeScored-V2.0,代码行数:20,代码来源:SpiderMatches.py

示例5: Worker

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
class Worker(QThread):
    update_ui_signal = pyqtSignal()

    def __init__(self, parent=None):
        QThread.__init__(self, parent)
        self.toDisplay = Queue()
        self.threadpool = ThreadPool(max_workers=cpu_count())

    def __del__(self):
        self.threadpool.shutdown()

    def compress_file(self, images, showapp, verbose, imagelist):
        """Start the worker thread."""
        for image in images:
            #FIXME:http://code.google.com/p/pythonthreadpool/issues/detail?id=5
            time.sleep(0.05)
            self.threadpool.add_job(image.compress, None,
                                    return_callback=self.toDisplay.put)
        self.showapp = showapp
        self.verbose = verbose
        self.imagelist = imagelist
        self.start()

    def run(self):
        """Compress the given file, get data from it and call update_table."""
        tp = self.threadpool
        while self.showapp or not (tp._ThreadPool__active_worker_count == 0 and
                                   tp._ThreadPool__jobs.empty()):
            image = self.toDisplay.get()

            self.update_ui_signal.emit()

            if not self.showapp and self.verbose: # we work via the commandline
                if image.retcode == 0:
                    ir = ImageRow(image)
                    print("File: " + ir['fullpath'] + ", Old Size: "
                        + ir['oldfilesizestr'] + ", New Size: "
                        + ir['newfilesizestr'] + ", Ratio: " + ir['ratiostr'])
                else:
                    print("[error] {} could not be compressed".format(image.fullpath), file=sys.stderr)
开发者ID:Kilian,项目名称:Trimage,代码行数:42,代码来源:trimage.py

示例6: deskWriteJob

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import add_job [as 别名]
import os
from Util import diskWriter

def deskWriteJob( arglist, kwargs):
    filewt = diskWriter()                                                       
    info = arglist[0]
    print "in the thread is:" + str(info)
    filename = (info["timestamp"].split(" ")[0]) + "-"+ info["dev_name"]                           
    filepath = "data/"+ info["dev_name"] + "/"                        
    targetpath = os.path.dirname(filepath)                                      
    if not os.path.isdir(targetpath):
        os.makedirs(targetpath)                                                 
    filename = filepath + filename                                              
    filewt.write( filename, str(info)+'\n')

print 'test ser start'
udp_server = UDPser( '127.0.0.1', 9876)
METAclient =()
tdpool = ThreadPool(10)
while True:
    data,addr = udp_server.readmeg()
    parsertest = Parser()
    info = parsertest.parserMeg(data)
    print "info json = "
    print info
    if info["dev_name"] not in METAclient:
        METAclient.__add__( tuple(info["dev_name"]))
    tdpool.add_job( deskWriteJob, info, info)
    print "out the thread is:" + str(info)

开发者ID:apophise,项目名称:Apophise,代码行数:31,代码来源:Ser.py


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