WindowsError [error 5] Access is denied

后端 未结 5 1033
無奈伤痛
無奈伤痛 2020-12-03 04:39

I\'m using the killableprocess package (built on top of subprocess) for running processes Whenever I run the \"killableprocess.Popen(command)\" piece of code in my script I

5条回答
  •  日久生厌
    2020-12-03 05:31

    Alternatively, if your module doesn't work, you can use the «subprocess» module:

    import subprocess, os, time
    
    process = subprocess.Popen("somecommand", shell=True)
    n = 0
    while True:
        if not process.poll():
            print('The command is running...')
            if n >= 10:
                pid = process.pid()
                os.kill(pid, 9) # 9 = SIGKILL
        else:
            print('The command is not running..')
        n += 1
        time.sleep(1) 
    

提交回复
热议问题