I have a loop and when the condition excel_active()
is true, it is an endless loop, and always try to read a .txt file and then execute it and then erase the content in .txt. It eats a lot of CPU when running.
What I want to ask is that is there any way to save the CPU besides time.sleep
?
Something like Watchdog (current version 0.9.0) in Linux? I am not familiar with Watchdog, can anyone give me some detailed suggestions?
while excel_active():
#time.sleep(0.5)
try:
with open(masterpath, 'r') as f:
s = f.read()
exec(s)
with open(masterpath,'w') as g:
g.truncate()
except:
pass
I really appreciate anyone's help!