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

如何让 for 循环在指定时间仍然结束的话自动 continue,并重新计数?

  •  
  •   Rudefish · 2018-05-29 16:46:40 +08:00 · 2443 次点击
    这是一个创建于 2159 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写了个 tumblr 的视频爬虫,vpn 掉了后即使重新连上网速恢复了,下载速度还是零点几 KB,用什么办法让指定时间后自动重新开始这个 for 循环?

    xpresslink
        1
    xpresslink  
       2018-05-29 17:02:02 +08:00
    import time
    while True:
    ****for xxxx
    ********do xxx
    ****time.sleep(60)
    Rudefish
        2
    Rudefish  
    OP
       2018-05-29 17:08:35 +08:00
    @xpresslink 你写的这个 for 循环不执行完,time.sleep 应该不会执行吧
    golmic
        3
    golmic  
       2018-05-29 17:10:43 +08:00
    while 1
    start = now
    for
    if now - start > 60
    break
    do
    Rudefish
        4
    Rudefish  
    OP
       2018-05-29 17:17:28 +08:00
    @golmic 卡住的地方应该是 video = requests.get ()这块,这个判断语句放在里面应该不会执行到吧
    golmic
        5
    golmic  
       2018-05-29 17:44:59 +08:00
    @Rudefish #4 requests.get(timeout=1)
    lniwn
        6
    lniwn  
       2018-05-29 18:58:36 +08:00
    aiohttp + asyncio.Timeout ?
    bigpigeon
        7
    bigpigeon  
       2018-05-30 10:15:36 +08:00
    我记得 python 的 req 模块有 timeout 参数的,用 scrapy 也应该有 timeout 参数的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2863 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:40 · PVG 20:40 · LAX 05:40 · JFK 08:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.