[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-03
2
Medium Priority
?
1,018 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:dolamitejenkins
2 Comments
 
LVL 3

Accepted Solution

by:
karl-henrik earned 2000 total points
ID: 36902455
Try
kernel32 = cdll.<dll name="kernel32.dll">
0
 

Author Closing Comment

by:dolamitejenkins
ID: 36904642
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question