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

同时抓取 10 个网站的网页,是用 multithread 还是 multiprocess?

  •  
  •   leafonsword ·
    leafonsword · 2014-07-24 20:46:48 +08:00 · 4314 次点击
    这是一个创建于 3535 天前的主题,其中的信息可能已经有所发展或是发生改变。
    循环10次太慢了,我想同时进行,我也知道multithread有GIL锁,所以multiprocess貌似是不错选择?
    我还听说过一些其他高并发项目,如:gevent、stackless、pypy,这些和官方多进程有何区别?
    11 条回复    2014-07-25 11:25:11 +08:00
    wy315700
        1
    wy315700  
       2014-07-24 20:51:05 +08:00   ❤️ 1
    multiprocess + pool 比较好

    multithread + gevent也可以
    heiher
        2
    heiher  
       2014-07-24 21:02:07 +08:00 via iPhone   ❤️ 3
    线程用来使用cpu资源的,像这种基本就是I/O为主,使用异步I/O不就好了。
    binux
        3
    binux  
       2014-07-24 21:14:00 +08:00
    GIL锁是锁语句执行的,IO等待又不会被锁
    bigdude
        4
    bigdude  
       2014-07-24 21:44:12 +08:00
    gevent
    ffffwh
        5
    ffffwh  
       2014-07-24 22:32:23 +08:00
    异步+1
    xavierskip
        6
    xavierskip  
       2014-07-24 22:40:05 +08:00
    我之前测试的时候,threading比gevent快耶。
    pandada8
        7
    pandada8  
       2014-07-24 23:54:48 +08:00 via Android
    处理速度永远大于你的抓取速度
    withrock
        8
    withrock  
       2014-07-25 08:57:21 +08:00
    我之前写过抓取糗事百科的虫,我的CPU有4个核,用threading的话,CPU的使用率不会超过25%。
    Zuckonit
        9
    Zuckonit  
       2014-07-25 09:31:41 +08:00
    gevent吧
    kingxsp
        10
    kingxsp  
       2014-07-25 10:10:44 +08:00
    gevent 或者 asyncio
    lianghui
        11
    lianghui  
       2014-07-25 11:25:11 +08:00
    prefork span with multithread
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2747 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:24 · PVG 20:24 · LAX 05:24 · JFK 08:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.