I have a somehow curious Python(3.x) problem:
Basically i just want to create a timer which calls an external program (.exe) at a predefined time - (simplified below, additionally there is a countdown output):
time.sleep(y)
x=popen("pathto.exe")
If i test my code everything works exactly as i want BUT only for small y. For large y (wait for more than a few hours), Python doesnt execute the popen command (but there arent any Errors as well). Any other "normal" code after the popen command (for example an Email notification in my case) works fine.
Im not entirely sure if this is a Windows (im working on 64bit Windows 7, disabled all energy saving features im aware of) or a Python problem but couldnt find a solution so far:
I tried several additional arguments for popen (Shell/no Shell, etc.) and tried to open the program/define X ahead of the waiting period and close it afterwards again but nothing solved this unfortunately.
Many Thanks!
Edit: more detailed code example:
while 1:
if time.mktime(trade2)<=time.time():
break
else:
dif=time.mktime(trade2)-time.time() # this is just for a visible countdown
aus=time.gmtime(dif)
sys.stdout.flush()
print("\b\b\b\b\b\b\b\b\b", end="\r")
print(aus[3],aus[4],aus[5], sep=":",end="")
time.sleep(0.5)
x=subprocess.Popen("c:/xyz/abc.exe")
print("Sending Mail...")
The print() is ALWAYS executed as expected, the Popen only when the countdown less than approx 1-2hours.
Sleep does not have a guaranteed wake up time. According to the docs sleep may last a longer or shorter amount of time than requested. I've answered this question before on SO, with alternatives.