Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import time
import sys
import os
import ctypes
ES_CONTINUOUS = 0x80000000
ES_AWAYMODE_REQUIRED = 0x00000040
ES_SYSTEM_REQUIRED = 0x00000001
ES_DISPLAY_REQUIRED = 0x00000002
ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
p = ['|', '/', '-', '\\']
os.system('cls')
while True:
for i in range(0, 4):
print('\r' + p[i] + ' Press Ctrl-C to allow computer to sleep', end='')
try:
time.sleep(2)
except(KeyboardInterrupt):
print('\nGoodbye')
sys.exit()
@jonasbits

This comment has been minimized.

Copy link
Owner Author

commented Oct 7, 2013

first this call get
"-2147483648"

then the rest of the time
"-2147483647"

@jonasbits

This comment has been minimized.

Copy link
Owner Author

commented Oct 8, 2013

i made a windows exe release with cx_freeze

@jonasbits

This comment has been minimized.

Copy link
Owner Author

commented Oct 11, 2013

better tab usage, python is very particular about that ;-)

@jbfuzier

This comment has been minimized.

Copy link

commented Feb 20, 2014

Just to clear things up regarding return code (conversion from unsigned int to hex)
first this call get
"-2147483648" -> 0x80000000 = ES_CONTINUOUS

then the rest of the time
"-2147483647" -> 0x80000001 = ES_CONTINUOUS | ES_SYSTEM_REQUIRED

@kbarnes3

This comment has been minimized.

Copy link

commented Dec 29, 2014

Thanks for this gist! I adapted it into a decorator that calls SetThreadExecution appropriately to ensure the computer doesn't go into standby while the decorated function is running. My forked gist is: https://gist.github.com/kbarnes3/3fb7d353e9bdd3efccd5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.