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


Python ThreadPool.poll方法代码示例

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


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

示例1: testImageDownload

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import poll [as 别名]
 def testImageDownload(self):
     logging.debug('Start at %s', datetime.now())
     url = 'http://f1.163.com'
     # url = 'http://news.sina.com.cn/photo/'
     work_request = WorkRequest(spider, url)
     pool = ThreadPool(10, work_request)
     pool.poll()
开发者ID:steve-fan,项目名称:threadpool,代码行数:9,代码来源:test.py

示例2: gits_download

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import poll [as 别名]
    def gits_download(self, url, output="/tmp", threads=20):

        if not self.output:
            self.output = output

        results = self.index(url, output=output)

        if not results:
            return

        args = [((i[0], i[1]), {}) for i in self.giturls]

        # ... and build a WorkRequest object for each item in data
        requests = makeRequests(self.callback,
                                args,
                                self.print_result,
                                self.handle_exception)

        main = ThreadPool(threads)

        for req in requests:
            main.putRequest(req)
            print "Work request #%s added." % req.requestID

        i = 0
        while True:
            try:
                main.poll()
                print "Main thread working...",
                print "(active worker threads: %i)" % (
                    threading.activeCount()-1, )
                if i == 10:
                    print "**** Adding 3 more worker threads..."
                    main.createWorkers(3)
                if i == 20:
                    print "**** Dismissing 2 worker threads..."
                    main.dismissWorkers(2)
                i += 1
            except KeyboardInterrupt:
                print "**** Interrupted!"
                break
            except NoResultsPending:
                print "**** No pending results."
                break
        if main.dismissedWorkers:
            print "Joining all dismissed worker threads..."
            main.joinAllDismissedWorkers()
开发者ID:rpurizaca,项目名称:python-programming,代码行数:49,代码来源:git_dump.py

示例3: run_prod

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import poll [as 别名]
def run_prod():
    cycle_count=1
    main = ThreadPool(num_workers=PARSER_THREAD_COUNT)
    while True:
        ADMIN_LOGGER.info("Starting cycle : "+str(cycle_count))
        reload(P_ROOT)
        process_list = [[e, __import__(P_ROOT.__name__ + '.' + e + '.main', fromlist=e)]  for e in P_ROOT.__all__]
        process_dict=dict(process_list)
        ADMIN_LOGGER.info("Executing process list : "+str(process_dict.items()))
        for proc_name in process_dict.keys():                
                proc=getattr(process_dict.get(proc_name),'Parser','None')
                main.putRequest(WorkRequest(proc_runner, args=(1,proc),callback=None))
                ADMIN_LOGGER.info("Started thread : "+proc_name)
                try:                    
                    main.poll()
                except NoResultsPending:
                        pass
                except :
                    ADMIN_LOGGER.error(traceback.format_exc())        
        main.wait()
        ADMIN_LOGGER.info("Sleeping for default LISTING_SLEEP_TIME : "+str(GLOBAL_SLEEP_TIME))
        time.sleep(GLOBAL_SLEEP_TIME)
        cycle_count= 1 if cycle_count > 9999 else cycle_count+1
开发者ID:anaved,项目名称:jobparser,代码行数:25,代码来源:proc_run.py

示例4: ThreadedHandler

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import poll [as 别名]
class ThreadedHandler(BaseHandler, threading.Thread):
    """Daemon thread that spawns a thread pool for sending Airbrake notices."""

    def __init__(self, settings):
        BaseHandler.__init__(self, settings)

        thread_name = 'Airbrake{0}-{1}'.format(self.__class__.__name__,
                                               os.getpid())
        threading.Thread.__init__(self, name=thread_name)

        self.n_threads = settings['threaded.threads']
        self.poll_interval = settings['threaded.poll_interval']

        self.daemon = True  # daemon thread -- important!
        self.pool = ThreadPool(self.n_threads)

        self.start()

    def report(self, payload):
        request = WorkRequest(
            self._submit,
            args=(payload,),
            exc_callback = _exception_handler
        )

        self.pool.putRequest(request)

    def run(self):
        """Poll the pool for results and process them."""

        while True:
            try:
                time.sleep(self.poll_interval)
                self.pool.poll()

            except NoResultsPending:
                pass
开发者ID:epii,项目名称:pyramid_airbrake,代码行数:39,代码来源:threaded.py

示例5: ThreadPool

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import poll [as 别名]
    size = 1024
    threads = 5

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    s.bind((host,port)) 
    s.listen(backlog)
    sock = [s]

    main = ThreadPool(threads)
    main.createWorkers(threads)

    while True:

        if exit == 1:
            main.joinAllDismissedWorkers()
            sys.exit()

        else:
            requests = makeRequests(use_client, sock)
            for req in requests:
                main.putRequest(req)
            updates = makeRequests(update_client, sock)
            for update in updates:
                main.putRequest(update)
            time.sleep(0.5)
            main.poll()
        s.close
    if main.dismissedWorkers:
        print("Joining all dismissed worker threads...")
        main.joinAllDismissedWorkers()
开发者ID:eoghanmartin,项目名称:Distributed_Systems,代码行数:32,代码来源:server.py


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