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
billlee
V2EX  ›  Python

我想用 gevent patch thread, 又想用 multiprocessing.pool, 有没有办法兼容?

  •  
  •   billlee · May 26, 2017 · 5889 views
    This topic created in 3262 days ago, the information mentioned may be changed or developed.

    由于用到了 pymongo, 需要 patch thread, 但 patch thread 又会破坏 multiprocessing.Queue.

    如果没有办法兼容,那大概就要用外部的 celery 代替 multiprocessing.pool 了吧?

    4 replies    2017-05-27 19:44:50 +08:00
    wentian
        1
    wentian  
       May 27, 2017
    gevent 自带 Pool
    billlee
        2
    billlee  
    OP
       May 27, 2017
    @wentian #1 Gevent 的 pool 是协程池吧,和进程池是不同的
    wwqgtxx
        3
    wwqgtxx  
       May 27, 2017 via iPhone
    『 patch thread 又会破坏 multiprocessing.Queue 』这句从哪里得到的?
    我用的时候这两个并不会冲突
    billlee
        4
    billlee  
    OP
       May 27, 2017
    @wwqgtxx #3 文档里这么说的,http://www.gevent.org/gevent.monkey.html#gevent.monkey.patch_thread, 我写了个测试代码,如果不指定 thread=false, 在这个程序是不能正常工作的,会一直阻塞,没有输出。

    你能说说你是怎么同时用这两个的吗?

    https://gist.github.com/anonymous/103d37ec001b9a583b90e5a5d6b63161
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2323 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:12 · PVG 13:12 · LAX 22:12 · JFK 01:12
    ♥ Do have faith in what you're doing.