V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
imxiaohan
V2EX  ›  Python

问一个Python的问题

  •  
  •   imxiaohan · Nov 21, 2011 · 5816 views
    This topic created in 5283 days ago, the information mentioned may be changed or developed.
    其实也不算是Python的问题 :)

    我用Python写了个脚步本来处理一些事情,要求是在1个小时内处理完。但如果工作量很大,1小时处理不完的话,该怎么办呢?因为新的1个小时,脚本要开始处理新的事情了。

    这个情况用Python该如何处理,运行两个脚本?还是有其他的思路?

    谢谢各位了!
    6 replies    1970-01-01 08:00:00 +08:00
    CoX
        1
    CoX  
       Nov 21, 2011
    记个开始时间,处理事情的时候先算下过了多久,如果超过1小时就停止。
    最原始的办法,不知道有没有更好的办法。
    xiaket
        2
    xiaket  
       Nov 21, 2011
    1. 处理时把处理对象拿出来, 保证下次处理时不会被重复处理.
    2. 处理时用多进程或多线程.
    chloerei
        3
    chloerei  
       Nov 21, 2011
    写个 pid 文件,已存在就不继续运行
    amxku
        4
    amxku  
       Nov 29, 2011
    xiaojay
        5
    xiaojay  
       Nov 29, 2011
    文件锁,保证一次一个实例
    zythum
        6
    zythum  
       Nov 29, 2011
    同楼上,加个锁就可以了。加锁的方式很多,挑自己习惯的就可以了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3066 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:35 · PVG 13:35 · LAX 22:35 · JFK 01:35
    ♥ Do have faith in what you're doing.