ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention

I'm trying to use SetThreadExecutionState to not allow windows to hibernate or go idle which reaks havoc with my program which runs for a long period of time with no data being entered but at times is suddenly called to action... I found this code and I want to us it but ... first I don't completely understand ctypes or kernel32.dll ... I keep getting this error  and How would I turn this into a safe thread ?

ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
File "C:\Python26\sign\windowsnosleep.py", line 40, in <module>
  sys.exit(main())
File "C:\Python26\sign\windowsnosleep.py", line 33, in main
  kernel32.SetThreadExecutionState(ctypes.c_int(ES_CONTINUOUS|ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED))

Open in new window


I don't understand the error and there is not alot of python information on this topic ... anyone have any ideas ?

import os
import sys
import signal
import threading
import ctypes
import win32api
import time

                  
                     
ES_SYSTEM_REQUIRED = 0x00000001
ES_CONTINUOUS = 0x80000000
ES_DISPLAY_REQUIRED =0x00000002
          

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|ES_DISPLAY_REQUIRED))
    event.wait()
    print 'Bye!'

    return 0

if __name__ == '__main__' :
    sys.exit(main()) 

Open in new window

dolamitejenkinsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

karl-henrikCommented:
Try
kernel32 = cdll.<dll name="kernel32.dll">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dolamitejenkinsAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.