V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jun 11, 2018 · 2025 views
    This topic created in 2879 days ago, the information mentioned may be changed or developed.

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

    wuwenzhx
        1
    wuwenzhx  
       Jun 11, 2018
    Manager 本身就是 python 用来实现共享内存的,Manager 中的 queue 当然是共享的啦,既然共享自然可以通信
    RicardoScofileld
        2
    RicardoScofileld  
    OP
       Jun 11, 2018
    @wuwenzhx 但是 multiprocessing 中的 Queue 不支持父子进程之间通信吗
    wwqgtxx
        3
    wwqgtxx  
       Jun 11, 2018
    Multprocessing.Queue 应该是用 pipe 实现的,如果父进程不及时把内容取走貌似会导致管道阻塞,至于 Multprocessing.Manager 是使用了类似于 tcp 通讯的方式,有后台线程持续读取 pipe 的消息,所以没事
    RicardoScofileld
        4
    RicardoScofileld  
    OP
       Jun 11, 2018
    @wwqgtxx 原来是这样,多谢指点
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3786 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 10:30 · PVG 18:30 · LAX 03:30 · JFK 06:30
    ♥ Do have faith in what you're doing.