社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

在python中,multiprocess.Queue.get()需要很长时间

Lau • 6 年前 • 600 次点击  

我需要通过遍历数据来获取真正大的数据块。我总共需要几百万次迭代。所以我以为减价会加快我的处理速度,结果就差不多了。我用 subprocess.Queue 要调用不同的线程,这实际上很好,但是当我调用*subprocess.Queue.get()时,程序将永远获取结果也许我做错了什么。下面是我的一个小例子:

def get_losses(self, tags=None):
    return_dict = {}
    output_list = multiprocessing.Queue()
    process_list = []

    # Create quese definition
    for experiment, path in self.tf_board_dicts.items():
        t = multiprocessing.Process(target=self._load_vec_from_tfboard, args=(path, tags, experiment))
        process_list.append(t)
    print("Starting subprocesse with a total of {} workers. \n These are  {}".format(len(process_list),
                                                                                         process_list))
    # Run processes
    for p in process_list:
        p.start()

    # Exit the finished threads
    for p in process_list:
        p.join()
    print("All subprocesses are termianted")

    # Get results
    results = [output_list.get() for p in process_list]
    print("All losses are gathered: {}".format([tup[0] for tup in results]))

    # Create dict
    for experiment_losses in results:
         return_dict[experiment_losses[0]] = experiment_losses[1]

    return return_dict
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48394