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

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

  •  
  •   billlee · 2017-05-26 23:31:50 +08:00 · 5137 次点击
    这是一个创建于 2497 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

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

    https://gist.github.com/anonymous/103d37ec001b9a583b90e5a5d6b63161
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3378 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:15 · PVG 21:15 · LAX 06:15 · JFK 09:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.