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

假期在家撸了一个 python 爬虫

  •  
  •   hellorocky728 · 2016-10-07 13:53:40 +08:00 · 5124 次点击
    这是一个创建于 2747 天前的主题,其中的信息可能已经有所发展或是发生改变。

    周末没事儿在家学了学 python 的 gevent 库,感觉老牛逼了,顺便写了一个简单的爬虫,比较了 gevent 和 multithread 和 multiprocessing.欢迎拍砖.另外,请教一个问题,脚本在运行多进程的时候总是报错:

    https://github.com/hellorocky/alexaTop500

    Traceback (most recent call last):
      File "alexa.py", line 116, in <module>
        site.multiprocess()
      File "alexa.py", line 83, in multiprocess
        self.domain = multiprocessing.Manager().list()
      File "/home/rocky/python/lib/python2.7/multiprocessing/managers.py", line 667, in temp
        token, exp = self._create(typeid, *args, **kwds)
      File "/home/rocky/python/lib/python2.7/multiprocessing/managers.py", line 565, in _create
        conn = self._Client(self._address, authkey=self._authkey)
      File "/home/rocky/python/lib/python2.7/multiprocessing/connection.py", line 175, in Client
        answer_challenge(c, authkey)
      File "/home/rocky/python/lib/python2.7/multiprocessing/connection.py", line 432, in answer_challenge
        message = connection.recv_bytes(256)         # reject large message
    IOError: [Errno 11] Resource temporarily unavailable
    
    15 条回复    2016-10-09 09:34:51 +08:00
    zwpaper
        1
    zwpaper  
       2016-10-07 14:23:18 +08:00 via iPhone
    手机没细看,瞎猜一下,是不是 Socket 端口占用没处理好
    hellorocky728
        2
    hellorocky728  
    OP
       2016-10-07 14:35:32 +08:00
    @zwpaper 应该不是吧,我都没有起服务,没有占用端口
    ericls
        3
    ericls  
       2016-10-07 14:57:10 +08:00
    试试 loop.run_in_executor 呢? 用 future 的形式来看看
    firebroo
        4
    firebroo  
       2016-10-07 15:04:20 +08:00 via Android
    resource xxx 报错应该是进程太多了
    stranbird
        5
    stranbird  
       2016-10-07 15:49:22 +08:00
    可以先用 pep8 lint 一下。
    pright
        6
    pright  
       2016-10-07 15:51:22 +08:00
    http://bugs.python.org/issue6056

    multiprocessing 的坑感觉有点多
    prasanta
        7
    prasanta  
       2016-10-07 22:46:27 +08:00
    为什么不用 aasync/await 呢
    panda0
        8
    panda0  
       2016-10-08 10:05:28 +08:00
    hellorocky728
        9
    hellorocky728  
    OP
       2016-10-08 10:17:29 +08:00
    @prasanta 这两天打算学学,然后用上,比较一下~
    rale
        10
    rale  
       2016-10-08 10:42:28 +08:00
    这个 errno 11 来自于 c 语言, http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html , 按这里的 define 你重试几次看看。
    hellorocky728
        11
    hellorocky728  
    OP
       2016-10-08 17:21:19 +08:00
    @rale 虽然不知道怎么做,但还是感谢~
    hellorocky728
        12
    hellorocky728  
    OP
       2016-10-08 17:21:37 +08:00
    @stranbird 谢谢
    ToughGuy
        13
    ToughGuy  
       2016-10-08 17:29:29 +08:00
    ulimit -a 看看
    hellorocky728
        14
    hellorocky728  
    OP
       2016-10-08 18:05:16 +08:00
    @ToughGuy

    `
    core file size (blocks, -c) 0
    data seg size (kbytes, -d) unlimited
    scheduling priority (-e) 0
    file size (blocks, -f) unlimited
    pending signals (-i) 3862
    max locked memory (kbytes, -l) 64
    max memory size (kbytes, -m) unlimited
    open files (-n) 10240
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    real-time priority (-r) 0
    stack size (kbytes, -s) 8192
    cpu time (seconds, -t) unlimited
    max user processes (-u) 3862
    virtual memory (kbytes, -v) unlimited
    file locks (-x) unlimited

    `
    ToughGuy
        15
    ToughGuy  
       2016-10-09 09:34:51 +08:00
    系统资源限制问题不大, 你代码里面多进程部分最好加上 queue, 限制同时 fork 的进程数量。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3625 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 04:49 · PVG 12:49 · LAX 21:49 · JFK 00:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.