• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Problem on wake of windows os

I have a problem the persist when my program sits idle (windows os) and it might be important in the compiled form , when it sits idle for a long time ... when you enter information it sometime throws and attribute error for one of the widgets the collects data ... the code works perfect otherwise ... so here is my thought what if I ran a thread that woke up the system every so often say every 10 minutes ? so my question is  is there a wake up the computer command ? if not then what is the best way to accomplish this ?
0
dolamitejenkins
Asked:
dolamitejenkins
  • 5
  • 4
1 Solution
 
gelonidaCommented:
My very first impression is, that solving the root cause might be better than trying to 'fake'  activity in order
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

0
 
dolamitejenkinsAuthor Commented:
I have disabled the hibernation / stand by and it has done it but not as frequently ... I have been searching for the cause for months and Im assuming its some conflict between windows and wxpthon or a glitch in my programming that I cant detect  ... I've been running the error tracing code you shared with me and nothing comes up ...
0
 
gelonidaCommented:
I see :-(

That's bad.

Did you try to upgrade or downgrade your python / wxPython versions???

If disabling  hibernation / standby doesn't work, then I'm not sure, whether SetThreadExecutionState()
will change anything.

You could still try it.

Not sure, whether I asked this already : Did you look whether you see anything suspicious in the windows event logs?

Just start evenvvwr from a cmd prompt
and walk through the Windows Logs Perhaps some weird message rings a bell.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
dolamitejenkinsAuthor Commented:
no I didn't try that.... i will check it and let you know what I find
0
 
dolamitejenkinsAuthor Commented:
I double checked and the problem is only when we come out of hibernate or stand by... when we turn it off we haven't had any problems
0
 
gelonidaCommented:
Then avoiding hibernate / standby seems an option.
calling every few minutes SetThreadExecutionState()
should probably do the job.

However I can't tell you the exact parameters as I never used this command myself
0
 
dolamitejenkinsAuthor Commented:
this is the tread i wrote and Im not sure it works


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() 

Open in new window


I found this code but I keep getting an error and I thing it's too complicated for my simple program
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

Open in new window


I know you havent worked with this code but does anything look suspicious with my code ?

   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())  

Open in new window

             
0
 
dolamitejenkinsAuthor Commented:
thanks
0
 
gelonidaCommented:
Is it working?
If not just reply here and I will post the correct call as soon as I had time to try it.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now