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

Python 如何看某个脚本的状态

  •  
  •   Ewig · Dec 20, 2018 · 2219 views
    This topic created in 2686 days ago, the information mentioned may be changed or developed.
    #!/usr/bin/python3
    import sys
    import datetime
    import os
    import time
    if __name__ == '__main__':
    while 1:
    startTime=datetime.datetime.now()
    main_path='./main.py'
    py=sys.executable
    status=os.system(r'{} {} {} {}'.format(py, main_path, sys.argv[1],sys.argv[2]))
    if status==0:
    time.sleep(120)
    else:
    endTime=datetime.datetime.now()
    if endTime-startTime>60*60:
    break



    我现在在程序里启一个脚本,我想判断这个脚本运行了超过 1 个小时就 kill 掉,如何写?
    5 replies    2018-12-21 10:50:25 +08:00
    Cooky
        1
    Cooky  
       Dec 20, 2018 via Android
    multiprocess
    lakechan96
        2
    lakechan96  
       Dec 20, 2018
    然后开一个线程开始 sleep,超时就 kill
    Ewig
        3
    Ewig  
    OP
       Dec 21, 2018
    @lakechan96 具体如何操作
    Ewig
        4
    Ewig  
    OP
       Dec 21, 2018
    @Cooky 具体如何操作
    Cooky
        5
    Cooky  
       Dec 21, 2018 via Android
    @Ewig RTFM
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:27 · PVG 21:27 · LAX 06:27 · JFK 09:27
    ♥ Do have faith in what you're doing.