Jump to content
Seminko

Computer goes into sleep mode while a script is running?

Recommended Posts

Seminko

I have a script that periodically grabs data from a website and puts them into a SQLite database. The whole rotation takes between 60 to 100 minutes and then sleeps for three hours. However, lately I had it set up so that it only grabs the data between 6AM and 7PM, otherwise a Sleep function is called repeatedly until it is 6AM again, and the whole thing started acting up. What usually took 60 - 100 minutes now can take several hours.

I haven't been able to pinpoint why. I have a pretty decent error checking and every error is being logged. I suspect it has something to do with the computer going to sleep (but that theory has holes, but you have to start somewhere, right).

So my questions are:

  • if I run a script and the mouse is not moving will the PC still be able to go into sleep mode? From what I've read on the forums it will.
  • Will the PC be able to go into sleep mode if a file is being written to, let's say, every minute and mouse not being moved at all?
  • What happens if a script is running and the PC goes into sleep mode?
  • What happens once the PC is awaken? Will the script continue where it left off?
  • Is there a possibility of a PC being waken up from sleep mode by something other than mouse movement? I ask because from the logs I can see that everything went fine, then there was a two / three / four hour period where nothing is logged and then it continued. It almost looks like the PC went to sleep, but after some hours it got woken up by something and continued.

Thanks,

S.

Share this post


Link to post
Share on other sites
JLogan3o13

What is the sleep/hibernation setting on the computer?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Seminko
10 minutes ago, JLogan3o13 said:

What is the sleep/hibernation setting on the computer?

Sleep mode after 30 minutes.

Share this post


Link to post
Share on other sites
AdamUL

Have a look at _WinAPI_SetThreadExecutionState.  

#include <WinAPIProc.au3>
 
;Enable away mode and prevent the sleep idle time-out.
_WinAPI_SetThreadExecutionState(BitOR($ES_CONTINUOUS, $ES_SYSTEM_REQUIRED, $ES_AWAYMODE_REQUIRED))


;Wait until process is complete...


;Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
_WinAPI_SetThreadExecutionState($ES_CONTINUOUS)

 

Adam

 

  • Like 1

Share this post


Link to post
Share on other sites
Seminko
7 minutes ago, AdamUL said:

Have a look at _WinAPI_SetThreadExecutionState.  

#include <WinAPIProc.au3>
 
;Enable away mode and prevent the sleep idle time-out.
_WinAPI_SetThreadExecutionState(BitOR($ES_CONTINUOUS, $ES_SYSTEM_REQUIRED, $ES_AWAYMODE_REQUIRED))


;Wait until process is complete...


;Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
_WinAPI_SetThreadExecutionState($ES_CONTINUOUS)

 

Adam

 

Thanks Adam, the thing is I can manually set the PC so that it never goes to sleep.

If I used this and the PC went to sleep after one loop is finished will I be able to wake it from sleep once another loop is due? I don't think that is the case right?

Edited by Seminko

Share this post


Link to post
Share on other sites
AdamUL

Your welcome.  It only keeps the computer from going to sleep while the process is running.  Another option is to use Task Scheduler, and create a task to run at the needed times.  There is an option under the Conditions tab to "Wake the computer to run this task" in the Create Task dialog box.    

 

Adam

 

  • Like 1

Share this post


Link to post
Share on other sites
junkew

Use sendkeys numlock on and numlock off it will keep your pc awake

Use autologon from sysinternals to automagically logon after shutdown -r -t 0

During start you then can run your script and at end turn screensaver on and have script wait to repeat reboot at a certain time. Webscraping is gui interaction which needs an unlocked machine.

Share this post


Link to post
Share on other sites
Seminko
17 minutes ago, AdamUL said:

Your welcome.  It only keeps the computer from going to sleep while the process is running.  Another option is to use Task Scheduler, and create a task to run at the needed times.  There is an option under the Conditions tab to "Wake the computer to run this task" in the Create Task dialog box.

So basically I could write the script in a way that it would only do one loop and stopped and schedule this task to be done in certain intervals right in the Task Scheduler, right?

That's actually a great idea, I will look into that!

Share this post


Link to post
Share on other sites
Seminko
3 hours ago, AdamUL said:

There is an option under the Conditions tab to "Wake the computer to run this task" in the Create Task dialog box. 

I decided to try a combination of both. I will run a scheduled task that will wake up the pc if necessary and use _WinAPI_SetThreadExecutionState to prevent sleep mode while the script is running.

In such a case I can remove $ES_AWAYMODE_REQUIRED, correct? So I would only use:

_WinAPI_SetThreadExecutionState(BitOR($ES_CONTINUOUS, $ES_SYSTEM_REQUIRED))

script

_WinAPI_SetThreadExecutionState($ES_CONTINUOUS)

 

Edited by Seminko

Share this post


Link to post
Share on other sites
AdamUL

Yes, you can remove $ES_AWAYMODE_REQUIRED.  Here the quote from MSDN.  

Quote

The ES_AWAYMODE_REQUIRED value should be used only when absolutely necessary by media applications that require the system to perform background tasks such as recording television content or streaming media to other devices while the system appears to be sleeping. Applications that do not require critical background processing or that run on portable computers should not enable away mode because it prevents the system from conserving power by entering true sleep. 

To enable away mode, an application uses both ES_AWAYMODE_REQUIRED and ES_CONTINUOUS; to disable away mode, an application calls SetThreadExecutionState with ES_CONTINUOUS and clears ES_AWAYMODE_REQUIRED. When away mode is enabled, any operation that would put the computer to sleep puts it in away mode instead. The computer appears to be sleeping while the system continues to perform tasks that do not require user input. Away mode does not affect the sleep idle timer; to prevent the system from entering sleep when the timer expires, an application must also set the ES_SYSTEM_REQUIRED value. 

From what you described in an earlier post, I thought that it fit this condition, that is why I included it.  I do not see a problem removing it.  

 

Adam

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.