ASKER
ASKER
ASKER
ASKER
import os
import sys
import signal
import threading
import ctypes
import win32api
import time
class WindowsNoSleep(threading.Thread):
def Run(self):
time.sleep(5)
SetThreadExecutionState(ctypes.c_int(ES_DISPLAY_REQUIRED|ES_CONTINUOUS|ES_SYSTEM_REQUIRED))
print SetThreadExecutionState(ctypes.c_int(ES_DISPLAY_REQUIRED|ES_CONTINUOUS|ES_SYSTEM_REQUIRED))
WindowsNoSleep().start()
Traceback (most recent call last):
File "C:\Python26\sign\windowsnosleep.py", line 38, in <module>
sys.exit(main())
File "C:\Python26\sign\windowsnosleep.py", line 31, in main
kernel32.SetThreadExecutionState(ctypes.c_int(ES_CONTINUOUS|ES_SYSTEM_REQUIRED))
ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
import sys
import signal
import threading
import ctypes
import win32api
import time
ES_SYSTEM_REQUIRED = 0x00000001
ES_CONTINUOUS = 0x80000000
event = threading.Event()
def ctrlc(signum, frame) :
event.set()
def main():
'''
Prevent system suspend when idle
'''
signal.signal(signal.SIGINT, ctrlc)
kernel32 = ctypes.CDLL('kernel32.dll')
print kernel32
time.sleep(500)
kernel32.SetThreadExecutionState(ctypes.c_int(ES_CONTINUOUS|ES_SYSTEM_REQUIRED))
event.wait()
print 'Bye!'
return 0
if __name__ == '__main__' :
sys.exit(main())
ASKER
Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.
TRUSTED BY
to work a round an unknown problem.
In order to identify the root cause:
- does the problem occur only after your system enetered standby mode or hybernate mode or does it
even occur after a certain time (with standby / hibernate disabled)
- try to write the smalles possible program still reproducing above behaviour.
If what you want to do is to avoid / standby / hibernate while your program is active, then on windows the call
SetThreadExecutionState() might be what you are looking for.
I never used this call myself, though I intend to play with in in the next weeks for one of my projects.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208%28v=vs.85%29.aspx