V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
RicardoScofileld
V2EX  ›  Python

一个关于 queue 的问题

  •  
  •   RicardoScofileld · 2018-06-11 10:24:44 +08:00 · 1609 次点击
    这是一个创建于 2117 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本来写一段代码,文件 IO 比较高,所以打算用多进程跑,子进程跑完的结果,通过放入 queue 中,最后再父进程中合并一下,但是子进程代码跑完就卡死了不动了。研究半天,最后把 from Multprocessing import Queue 换成了 from multiprocessing import Manager 中的 queue,然后代码可以跑完了,想了想是因为 Queue 只支持子进程通信,而 Manager 中的 queue 支持父子进程通信吗?

    wuwenzhx
        1
    wuwenzhx  
       2018-06-11 15:41:41 +08:00
    Manager 本身就是 python 用来实现共享内存的,Manager 中的 queue 当然是共享的啦,既然共享自然可以通信
    RicardoScofileld
        2
    RicardoScofileld  
    OP
       2018-06-11 16:30:43 +08:00
    @wuwenzhx 但是 multiprocessing 中的 Queue 不支持父子进程之间通信吗
    wwqgtxx
        3
    wwqgtxx  
       2018-06-11 18:42:45 +08:00
    Multprocessing.Queue 应该是用 pipe 实现的,如果父进程不及时把内容取走貌似会导致管道阻塞,至于 Multprocessing.Manager 是使用了类似于 tcp 通讯的方式,有后台线程持续读取 pipe 的消息,所以没事
    RicardoScofileld
        4
    RicardoScofileld  
    OP
       2018-06-11 19:24:21 +08:00
    @wwqgtxx 原来是这样,多谢指点
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   999 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 543ms · UTC 22:14 · PVG 06:14 · LAX 15:14 · JFK 18:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.