推荐学习书目
› 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 · 2625 views
    This topic created in 2897 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
    Cooky
    Dec 20, 2018 via Android
    1
    multiprocess
    lakechan96
    lakechan96
    Dec 20, 2018
    2
    然后开一个线程开始 sleep,超时就 kill
    Ewig
    Ewig
    OP
    Dec 21, 2018
    3
    @lakechan96 具体如何操作
    Ewig
    Ewig
    OP
    Dec 21, 2018
    4
    @Cooky 具体如何操作
    Cooky
    Cooky
    Dec 21, 2018 via Android
    5
    @Ewig RTFM
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4155 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:57 · PVG 16:57 · LAX 00:57 · JFK 03:57
    ♥ Do have faith in what you're doing.