Windows still going to sleep whilst downloading

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
TheWedgie
Newbie
Newbie
Posts: 1
Joined: November 23rd, 2010, 7:51 pm

Windows still going to sleep whilst downloading

Post by TheWedgie »

Howdy all, SABnzbd 0.5.6 on Windows 7 x64...

Using the basic Windows power settings - with "Put the computer to sleep" set to 30 minutes.

It seems SABnzbd isn't stopping Windows from going to sleep - as I've watched go to sleep after 30 minutes of inactivity.
I can't seem to find any threads relating to a recent version of SAB though, most of them are from ~2008.

Thoughts as to where I can look? I couldn't find any settings in SAB itself - assumed the 'stay awake' stuff was built in?

Cheers,
Nick

User avatar
shypike
Administrator
Administrator
Posts: 21039
Joined: January 18th, 2008, 12:49 pm

Re: Windows still going to sleep whilst downloading

Post by shypike »

TheWedgie wrote: assumed the 'stay awake' stuff was built in?
Yes it is, although I haven't tested it for ages because the code never changed.
Basically it does a periodic SetThreadExecutionState(ES_SYSTEM_REQUIRED) system call
while still downloading and postprocessing.

methanoid
Newbie
Newbie
Posts: 47
Joined: March 7th, 2008, 6:33 am

Re: Windows still going to sleep whilst downloading

Post by methanoid »

So, is there or is there not an issue with SAB and Sleep? Curious really but I am wondering about using Sleep as my wife claims she can hear the PC at night (need to club her harder!)  8)

User avatar
shypike
Administrator
Administrator
Posts: 21039
Joined: January 18th, 2008, 12:49 pm

Re: Windows still going to sleep whilst downloading

Post by shypike »

Do you happen to have individually paused items in your queue?
I suspect that having these will make SABnzbd think the queue isn't really empty,
so it keeps kicking Windows awake.
I must look into that.
BTW: this is the opposite of what "TheWedgie" complained about...

anita42
Newbie
Newbie
Posts: 3
Joined: February 22nd, 2020, 8:52 am

Re: Windows still going to sleep whilst downloading

Post by anita42 »

Hi,

First of all, thanks to all the people contributing to the development of sabnzbd. I'm using it for years now and I am super happy with it! :)

Now my question:
I have recently bought a brand new machine (intel NUC10i7FNK2) with Windows 10 which I use as a download and media center. I have intentionally instructed Windows to put the machine to sleep after 10 minutes of idle time which works fine, in principle. However, the problem that I experience now is that Windows goes to sleep even if sabnzbd is still in the middle of downloading sth. This is quite annoying.

I should mention that I had an older NUC with Windows 7 before which worked flawlessly in this setup for years with sabnzbd. I never experienced this issue during that time.

A thing which came to my mind and which probably makes a difference here is that the new machine has a big and super fast SSD. The files in sabnzbd are downloaded first to a local folder on that SSD and are processed there. Afterwards, everything is shifted to a NAS in my home network. Before, i.e. with the older machine, the files were downloaded directly to a folder on the NAS and processed there which was always rather slow and caused a lot of network traffic. But maybe exactly this network traffic prevented Windows of putting the computer to sleep!?

I would be grateful for any ideas / suggestions. I love sabnzbd and still want to use it!! Thank you very much in advance!

anita

Puzzled
Newbie
Newbie
Posts: 47
Joined: September 2nd, 2017, 3:02 am

Re: Windows still going to sleep whilst downloading

Post by Puzzled »

I think it may need the ES_CONTINUOUS flag in addition to ES_SYSTEM_REQUIRED.

User avatar
safihre
Administrator
Administrator
Posts: 3595
Joined: April 30th, 2015, 7:35 am
Location: Switzerland
Contact:

Re: Windows still going to sleep whilst downloading

Post by safihre »

@Puzzled: We set the the state every 30 seconds, maybe that's not enough? We can do it every 3 seconds.
From the documentation a periodic call with ES_SYSTEM_REQUIRED should be enough?
https://docs.microsoft.com/en-us/window ... utionstate

anita42
Newbie
Newbie
Posts: 3
Joined: February 22nd, 2020, 8:52 am

Re: Windows still going to sleep whilst downloading

Post by anita42 »

Dear Puzzled and safihre,

Thank you very much for answering! After some testing, I think I can now with some confidence claim that I found the solution. The following works robustly at least for my system using Windows 10 Pro:

The 'magic' was given by Puzzled: it indeed needs the ES_CONTINUOUS flag in addition to ES_SYSTEM_REQUIRED. And you only need to call it once, that's completely enough. Setting the state periodically only with ES_SYSTEM_REQUIRED - no matter what's the frequency, like 3 seconds or 30 seconds - doesn't work at all. Actually, when you look at the code snippet on the bottom of the Microsoft website provided by safihre, the above solution is also more or less stated there.

How did I find it out? First of all, I set Windows to a very aggressive power saving mode. I told it to put both the monitor and the computer itself to energy saving mode after 1 minute. Then I used my extremely limited coding capabilities in Python to create the following kind of 'minimal testing script':

Code: Select all

import ctypes
import time

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

ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)

time.sleep(300)

ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
Result: After staying awake for 6 minutes (5 due to time.sleep(300) + 1 due to system idle), the computer goes to sleep, as could be expected. By the way, if you remove the ES_DISPLAY_REQUIRED flag above, only the monitor goes to sleep but the computer itself stays awake.

Could anyone of you guys be so nice to confirm this? That would be great! And if yes, would it be possible to modify sabnzbd in the future accordingly?

Thank you very much again and kind regards

anita

User avatar
safihre
Administrator
Administrator
Posts: 3595
Joined: April 30th, 2015, 7:35 am
Location: Switzerland
Contact:

Re: Windows still going to sleep whilst downloading

Post by safihre »

Change the code! WIll be in the next release.

anita42
Newbie
Newbie
Posts: 3
Joined: February 22nd, 2020, 8:52 am

Re: Windows still going to sleep whilst downloading

Post by anita42 »

safihre wrote:
March 6th, 2020, 8:20 am
Change the code! WIll be in the next release.
Great!! Thank you so much!!

Post Reply