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


Python process.ProcessPoolExecutor方法代码示例

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


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

示例1: main

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def main():
    urls = [
        'https://talkpython.fm',
        'https://pythonbytes.fm',
        'https://google.com',
        'https://realpython.com',
        'https://training.talkpython.fm/',
    ]

    work = []

    with PoolExecutor() as executor:
        for url in urls:
            # print("Getting title from {}".format(url.replace('https', '')),
            #       end='... ',
            #       flush=True)
            # title = get_title(url)
            f: Future = executor.submit(get_title, url)
            work.append(f)

        print("Waiting for downloads...", flush=True)

    print("Done", flush=True)
    for f in work:
        print("{}".format(f.result()), flush=True) 
开发者ID:talkpython,项目名称:async-techniques-python-course,代码行数:27,代码来源:program.py

示例2: musicSpider

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def musicSpider():
    print("======= 开始爬 音乐 信息 ===========")
    startTime = datetime.datetime.now()
    print(startTime.strftime('%Y-%m-%d %H:%M:%S'))
    # 所有专辑数量
    albums_num = sql.get_all_album_num()
    print("所有专辑数量:", albums_num)
    # 批次
    batch = math.ceil(albums_num.get('num') / 1000.0)
    # 构建线程池
    # pool = ProcessPoolExecutor(1)
    for index in range(0, batch):
        saveMusicBatch(index)
        # pool.submit(saveMusicBatch, index)
    # pool.shutdown(wait=True)
    print("======= 结束爬 音乐 信息 ===========")
    endTime = datetime.datetime.now()
    print(endTime.strftime('%Y-%m-%d %H:%M:%S'))
    print("耗时:", (endTime - startTime).seconds, "秒")

# if __name__ == '__main__':
#     musicSpider() 
开发者ID:NacedWang,项目名称:163MusicSpider,代码行数:24,代码来源:music_by_album.py

示例3: lyricSpider

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def lyricSpider():
    print("======= 开始爬 歌词 信息 ===========")
    startTime = datetime.datetime.now()
    print(startTime.strftime('%Y-%m-%d %H:%M:%S'))
    # 所有歌手数量
    musics_num = sql.get_all_music_num()
    # 批次
    batch = math.ceil(musics_num.get('num') / 1000.0)
    # 构建线程池
    # pool = ProcessPoolExecutor(1)
    for index in range(0, batch):
        saveLyricBatch(index)
        # pool.submit(saveLyricBatch, index)
    # pool.shutdown(wait=True)
    print("======= 结束爬 歌词 信息 ===========")
    endTime = datetime.datetime.now()
    print(endTime.strftime('%Y-%m-%d %H:%M:%S'))
    print("耗时:", (endTime - startTime).seconds, "秒")

# if __name__ == '__main__':
#     lyricSpider() 
开发者ID:NacedWang,项目名称:163MusicSpider,代码行数:23,代码来源:lyric_by_music.py

示例4: commentSpider

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def commentSpider():
    print("======= 开始爬 评论 信息 ===========")
    startTime = datetime.datetime.now()
    print(startTime.strftime('%Y-%m-%d %H:%M:%S'))
    # 所有歌手数量
    musics_num = sql.get_all_music_num()
    # 批次
    batch = math.ceil(musics_num.get('num') / 1000.0)
    # 构建线程池
    # pool = ProcessPoolExecutor(1)
    for index in range(0, batch):
        saveCommentBatch(index)
        # pool.submit(saveCommentBatch, index)
    # pool.shutdown(wait=True)
    print("======= 结束爬 评论 信息 ===========")
    endTime = datetime.datetime.now()
    print(endTime.strftime('%Y-%m-%d %H:%M:%S'))
    print("耗时:", (endTime - startTime).seconds, "秒")

# if __name__ == '__main__':
#     commentSpider() 
开发者ID:NacedWang,项目名称:163MusicSpider,代码行数:23,代码来源:comments_by_music.py

示例5: test_init_cpu

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def test_init_cpu(dist_init_method):
    args = argparse.Namespace(
        multiprocessing_distributed=True,
        dist_world_size=2,
        dist_rank=None,
        ngpu=0,
        local_rank=None,
        dist_launcher=None,
        distributed=True,
        dist_backend="gloo",
        dist_init_method=dist_init_method,
        dist_master_addr=None,
        dist_master_port=None,
    )
    args.dist_rank = 0
    option = build_dataclass(DistributedOption, args)
    args.dist_rank = 1
    option2 = build_dataclass(DistributedOption, args)
    with ProcessPoolExecutor(max_workers=2) as e:
        fn = e.submit(option.init)
        fn2 = e.submit(option2.init)
        fn.result()
        fn2.result() 
开发者ID:espnet,项目名称:espnet,代码行数:25,代码来源:test_distributed_utils.py

示例6: test_init_cpu2

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def test_init_cpu2():
    args = argparse.Namespace(
        multiprocessing_distributed=True,
        dist_world_size=2,
        dist_rank=None,
        ngpu=0,
        local_rank=None,
        dist_launcher=None,
        distributed=True,
        dist_backend="gloo",
        dist_init_method="env://",
        dist_master_addr=None,
        dist_master_port=free_port(),
    )
    args.dist_rank = 0
    option = build_dataclass(DistributedOption, args)
    args.dist_rank = 1
    option2 = build_dataclass(DistributedOption, args)
    with ProcessPoolExecutor(max_workers=2) as e:
        fn = e.submit(option.init)
        fn2 = e.submit(option2.init)
        with pytest.raises(RuntimeError):
            fn.result()
            fn2.result() 
开发者ID:espnet,项目名称:espnet,代码行数:26,代码来源:test_distributed_utils.py

示例7: test_init_cpu4

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def test_init_cpu4():
    args = argparse.Namespace(
        multiprocessing_distributed=True,
        dist_world_size=2,
        dist_rank=None,
        ngpu=0,
        local_rank=None,
        dist_launcher=None,
        distributed=True,
        dist_backend="gloo",
        dist_init_method="env://",
        dist_master_addr="localhost",
        dist_master_port=free_port(),
    )
    args.dist_rank = 0
    option = build_dataclass(DistributedOption, args)
    args.dist_rank = 1
    option2 = build_dataclass(DistributedOption, args)
    with ProcessPoolExecutor(max_workers=2) as e:
        fn = e.submit(option.init)
        fn2 = e.submit(option2.init)
        fn.result()
        fn2.result() 
开发者ID:espnet,项目名称:espnet,代码行数:25,代码来源:test_distributed_utils.py

示例8: test_init_cpu5

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def test_init_cpu5():
    args = argparse.Namespace(
        multiprocessing_distributed=True,
        dist_world_size=2,
        dist_rank=None,
        ngpu=0,
        local_rank=None,
        dist_launcher=None,
        distributed=True,
        dist_backend="gloo",
        dist_init_method="env://",
        dist_master_addr="localhost",
        dist_master_port=free_port(),
    )
    args.dist_rank = 0
    option = build_dataclass(DistributedOption, args)
    args.dist_rank = 1
    option2 = build_dataclass(DistributedOption, args)
    with ProcessPoolExecutor(max_workers=2) as e:
        fn = e.submit(option.init)
        fn2 = e.submit(option2.init)
        fn.result()
        fn2.result() 
开发者ID:espnet,项目名称:espnet,代码行数:25,代码来源:test_distributed_utils.py

示例9: process_all

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def process_all(self, texts: Collection[str]) -> List[List[str]]:
        "Process a list of `texts`."
        if self.n_cpus <= 1:
            return self._process_all_1(texts)
        with ProcessPoolExecutor(self.n_cpus) as e:
            return sum(
                e.map(self._process_all_1, partition_by_cores(texts, self.n_cpus)), []
            ) 
开发者ID:jrzaurin,项目名称:pytorch-widedeep,代码行数:10,代码来源:fastai_transforms.py

示例10: __init__

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def __init__(self, num_workers):
        '''
            Create a process pool for concurrent execution with specified number of workers.
        '''
        self.executor_pool = ProcessPoolExecutor(num_workers) 
开发者ID:tanwanirahul,项目名称:django-batch-requests,代码行数:7,代码来源:executor.py

示例11: __init__

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def __init__(self, executor: ProcessPoolExecutor):
        self._executor = executor
        self._loop = asyncio.get_event_loop() 
开发者ID:vmagamedov,项目名称:grpclib,代码行数:5,代码来源:server.py

示例12: main

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    with ProcessPoolExecutor(max_workers=4) as executor:
        server = Server([Primes(executor)])
        with graceful_exit([server]):
            await server.start(host, port)
            print(f'Serving on {host}:{port}')
            await server.wait_closed() 
开发者ID:vmagamedov,项目名称:grpclib,代码行数:9,代码来源:server.py

示例13: test_resolve_distributed_mode_slurm3

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def test_resolve_distributed_mode_slurm3():
    args = argparse.Namespace(
        multiprocessing_distributed=True,
        dist_world_size=None,
        dist_rank=None,
        ngpu=1,
        local_rank=None,
        dist_launcher="slurm",
        dist_backend="nccl",
        dist_init_method="env://",
        dist_master_addr=None,
        dist_master_port=10000,
    )
    env = dict(
        SLURM_PROCID="0",
        SLURM_NTASKS="1",
        SLURM_STEP_NUM_NODES="1",
        SLURM_STEP_NODELIST="localhost",
        SLURM_NODEID="0",
        CUDA_VISIBLE_DEVICES="0,1",
    )

    e = ProcessPoolExecutor(max_workers=2)
    with unittest.mock.patch.dict("os.environ", dict(env, SLURM_LOCALID="0")):
        resolve_distributed_mode(args)
        option = build_dataclass(DistributedOption, args)
        fn = e.submit(option.init)

    with unittest.mock.patch.dict("os.environ", dict(env, SLURM_LOCALID="0")):
        option2 = build_dataclass(DistributedOption, args)
        fn2 = e.submit(option2.init)

    fn.result()
    fn2.result() 
开发者ID:espnet,项目名称:espnet,代码行数:36,代码来源:test_distributed_utils.py

示例14: __init__

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def __init__(self, max_workers=None):
        if max_workers is None:
            max_workers = _utils.get_optimal_process_count()
        super(ProcessPoolExecutor, self).__init__(max_workers=max_workers)
        if self._max_workers <= 0:
            raise ValueError("Max workers must be greater than zero")
        self._gatherer = _Gatherer(
            # Since our submit will use this gatherer we have to reference
            # the parent submit, bound to this instance (which is what we
            # really want to use anyway).
            super(ProcessPoolExecutor, self).submit,
            self.threading.lock_object) 
开发者ID:openstack,项目名称:futurist,代码行数:14,代码来源:_futures.py

示例15: _set_executor_pool

# 需要导入模块: from concurrent.futures import process [as 别名]
# 或者: from concurrent.futures.process import ProcessPoolExecutor [as 别名]
def _set_executor_pool(self) -> None:
        """Set thread pool pool to be used."""
        self._executor_pool = ProcessPoolExecutor(max_workers=len(self._tasks)) 
开发者ID:fetchai,项目名称:agents-aea,代码行数:5,代码来源:multiple_executor.py


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