假期在家撸了一个 python 爬虫 - V2EX
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 5808 次点击
    这是一个创建于 3298 天前的主题,其中的信息可能已经有所发展或是发生改变。

    周末没事儿在家学了学 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
    ikw
        1
    ikw  
       2016-10-07 14:23:18 +08:00 via iPhone
    手机没细看,瞎猜一下,是不是 Socket 端口占用没处理好
    hellorocky728
        2
    hellorocky728  
    OP
       2016-10-07 14:35:32 +08:00
    @zwpaper 应该不是吧,我都没有起服务,没有占用端口
    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     Solana     2444 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 15:37 PVG 23:37 LAX 08:37 JFK 11:37
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86