Windows 7/Vista process management - how to start an external program after long idle time?

强颜欢笑 提交于 2019-12-11 01:33:00

问题


This is a follow-up to that question.

Basically, i have a python script which should start another program (.exe) via a timer after some 2-6 hours. Everything works fine as long as i test it with a short countdown or as long as the computer is "active" (=userinput before, screen on) before the timer expires or as long there is no other program working at the same time (an Excel VBA script in my case).

On Windows 7, for long countdowns and with Excel running, the external program just doesnt open. There arent any Error messages and any other (python-internal) commands AFTER that are executed as they should.

Im using the x=subprocess.Popen([program,args],flags) command and tried almost all possible flags (Shell, buffersize, creationflags,stdout etc.) and alternatives (call) but it behaves always as described above.

Now i noticed a similar behaviour when trying to open the external program via VBA, so i dont think its a Python-specific but a Windows-specific problem. Additionally i tried it on another PC with Windows Vista and there it works surprisingly (both 64-bit if that matters).

I already tried increasing the process priority or prevent idle state via SetThreadExecutionState and disabled all energy-saving features i´am aware of, but nothing changed so far.

Does anyone have an idea? Many thanks, im getting frustrated slowly...


回答1:


After taking account the problem stated in Here, I think a viable alternative would be to use many short pauses instead of a long pause, so the program is always active, but may result in higher memory usage.

def wait(sec,sleeptime = 0):
    import time
    endsecs = time.time() + sec
    while True:
        if endsecs <= time.time():
            return None
        if sleeptime != 0:
            time.sleep(sleeptime)

Just a guess, nothing certain, no time to verify.



来源:https://stackoverflow.com/questions/9123165/windows-7-vista-process-management-how-to-start-an-external-program-after-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!