推荐学习书目
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
yixiugegegege
V2EX  ›  Python

关于 Python 多线程爬虫,线程假死的问题

  •  
  •   yixiugegegege · Nov 20, 2018 · 3007 views
    This topic created in 2758 days ago, the information mentioned may be changed or developed.

    这几天在搞 boss 直聘,全国数据.

    写了个多线程爬虫, 晚上挂到服务器上爬虫速度杠杠滴, 第二天来看爬虫速度巨慢无比,

    我是开的 300 线程,

    查看服务器状态, cpu 内存, 带宽 非常正常,

    然后网上查查资料 可能是 TCP 的端口占用 TIME_WAIT 太多, 导致服务器可用端口耗尽,

    但是我测试了一下 10 个线程, 发现还是会变慢,

    然后考虑到可能是线程假死了,,

    代码大概: requests 请求全部加了 timeout ;

    需要对数据库操作的方法都写了对 mysql 的连接; 更新,查找操作都加了线程锁;

    while true 循环 break 加好了都

    那么问题来了,大佬们,我怎么判断出是哪个步骤假死了,

    如果判断不出来, 有没有操作 可以重启这个线程..

    或者大佬们有没有遇到过这种情况,求指点

    2 replies    2018-11-20 18:08:03 +08:00
    wlsnx
        1
    wlsnx  
       Nov 20, 2018
    代码呢?
    yixiugegegege
        2
    yixiugegegege  
    OP
       Nov 20, 2018
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3120 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    ♥ Do have faith in what you're doing.