Standby

Want something added? Ask for it here.
methanoid
Jr. Member
Jr. Member
Posts: 66
Joined: March 7th, 2008, 6:33 am

Standby

Post by methanoid »

On queue finish

Shutdown PC
Hibernate PC
Shutdown SABnzbd

Why not Standby PC? Personally I never use Hibernate and I never shutdown SAB as its always handy to just be able to dump any NZB into the "hole" and have it download without having to worry that SAB is active but I do use Standby a helluva lot!

How about it?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

I'll have a look at this.
Funny thing, people also complain that the system goes into standby while SABnzbd is still busy.
So I'm also looking at letting SABnzbd tell the OS, not to standby...
User avatar
neilt0
Full Member
Full Member
Posts: 120
Joined: January 22nd, 2008, 4:16 am

Re: Standby

Post by neilt0 »

I use this script to put my Windows PC in to standby after the queue empties:

rundll32 powrprof.dll,SetSuspendState
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

Standby will be a  feature in the next release.
elfurbe
Newbie
Newbie
Posts: 7
Joined: January 23rd, 2008, 2:22 am

Re: Standby

Post by elfurbe »

neilt0 wrote: I use this script to put my Windows PC in to standby after the queue empties:

rundll32 powrprof.dll,SetSuspendState
When I do that, I get hibernate every time.  Even if you throw the 0,0,0 at the end to supposedly force it to sleep and not hibernate, it hibernates.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

You use either
rundll32 powrprof.dll,SetSuspendState Hibernate

or

rundll32 powrprof.dll,SetSuspendState Standby

Without the extra parameter you get the default action (often hibernate).
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

http://msdn.microsoft.com/en-us/library/aa373208.aspx

can you do that in python?

hope it helps else i will look more as i need it :)
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

It's on the to-do list as Ticket #4, with no plan yet.
I have looked at this before, but did not implement it.
The problem isn't in the calls itself (which are easy to do in Python)
but in finding out when exactly to call them.
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

"Calling SetThreadExecutionState without ES_CONTINUOUS simply resets the idle timer; to keep the display or system in the working state, the thread must call SetThreadExecutionState periodically.

To run properly on a power-managed computer, applications such as fax servers, answering machines, backup agents, and network management applications must use both ES_SYSTEM_REQUIRED and ES_CONTINUOUS when they process events. Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input. Applications such as word processors, spreadsheets, browsers, and games do not need to call "

Create Thread -
while [true]
  if (downloading or extracting)  SetThreadExecutionState(ES_SYSTEM_REQUIRED)
  sleep(1000)



greetings
daniel
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

*bump*
if you can give me small hints where to start looking i might wanna check that myself
waking my machine up and queue something just to see it going down again 5 mins later is not cool ;)

i have no idea how to do the call itself you have a howto on that?
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

oki did look into it - you are rights its a 3 mins find

Code: Select all

from ctypes import *
import os

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

def master_main():
	kernel32  = windll.LoadLibrary("Kernel32.dll")
	kernel32.SetThreadExecutionState(c_int(ES_SYSTEM_REQUIRED))
if (__name__ == "__main__"):
	master_main()



question now is where to put it in sabnzb - i did a quick peek in downloader.py  and didnt understand it 100% right away in a minute
the queue emtpy case is not clear for me without looking more - maybe you can help me with it - but reading msdn correctly its not even needed

so maybe this already is the solution (as a diff) - i *didnt* run it yet only checked if it compiles
will report again once i had time to run it

Code: Select all

--- old\downloader.py   2008-11-03 21:36:58.000000000 +0100
+++ downloader.py       2008-11-20 00:58:32.031125000 +0100
@@ -34,8 +34,14 @@
 from sabnzbd.misc import Notify, decodePassword
 from sabnzbd.constants import *

+from ctypes import *
+
 #------------------------------------------------------------------------------

+ES_SYSTEM_REQUIRED  = 0x00000001
+ES_DISPLAY_REQUIRED = 0x00000002
+ES_CONTINUOUS = 0x80000000
+
 def GetParm(server, keyword):
     """ Get named server parameter in a safe way """
     try:
@@ -131,6 +137,12 @@
     def __init__(self, servers, paused = False):
         Thread.__init__(self)

+        try:
+           self.kernel32  = windll.LoadLibrary("Kernel32.dll")
+        except:
+           kernel32 = False
+           pass
+
         # Used for scheduled pausing
         self.paused = paused

@@ -470,6 +482,12 @@
                          __NAME__, nw.thrdnum, nw.server.host,
                          nw.server.port, nw.article.article)

+            if kernel32:
+               try:
+                  kernel32.SetThreadExecutionState(c_int(ES_SYSTEM_REQUIRED))
+               except:
+                  pass
+
             fileno = nw.nntp.sock.fileno()

             nw.body()
Cya
Daniel
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

It's an accepted ticket waiting to be implemented.
When it has enough priority and someone of team wants to do it.
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

i cant make it run with the exe version of sabnzb (or compile a new one using py2exe) as im not a python expert and its missing the _ctypes but its running now with a full blown python

apart from that, i made some minor changes made to improve compatibility

Code: Select all

--- old\downloader.py   2008-11-03 21:36:58.000000000 +0100
+++ SABnzbd\downloader.py       2008-11-20 13:49:59.890500000 +0100
@@ -26,6 +26,9 @@
 import logging
 import sabnzbd
 import datetime
+import os
+if os.name=='nt':
+   import ctypes

 from threading import Thread

@@ -34,8 +37,15 @@
 from sabnzbd.misc import Notify, decodePassword
 from sabnzbd.constants import *

+if os.name=='nt':
+   from ctypes import *
+
 #------------------------------------------------------------------------------

+ES_SYSTEM_REQUIRED  = 0x00000001
+ES_DISPLAY_REQUIRED = 0x00000002
+ES_CONTINUOUS = 0x80000000
+
 def GetParm(server, keyword):
     """ Get named server parameter in a safe way """
     try:
@@ -131,6 +141,13 @@
     def __init__(self, servers, paused = False):
         Thread.__init__(self)

+        self.kernel32 = False
+        if os.name == "nt":
+           try:
+              self.kernel32 = windll.LoadLibrary("Kernel32.dll")
+           except:
+              pass
+
         # Used for scheduled pausing
         self.paused = paused

@@ -470,6 +487,12 @@
                          __NAME__, nw.thrdnum, nw.server.host,
                          nw.server.port, nw.article.article)

+            if self.kernel32:
+               try:
+                  self.kernel32.SetThreadExecutionState(c_int(ES_SYSTEM_REQUIRED))
+               except:
+                  pass
+
             fileno = nw.nntp.sock.fileno()

             nw.body()
do i read your post right, that you are not really an open community and dont care to much about input like this? doesnt have to be bad! I would then  simply dont nag you anymore, but just simply fix it for myself or ask one of my employees who are python geeks then.


BTW: do you by any chance have a full dev env for sabnzbd which also contains the py2exe build files etc?  Ahh yeah and your py2exe link in the install.txt is broken.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Standby

Post by shypike »

We have limited time to work on SABnzbd and have to make choices.
We welcome patches for fixes and new features, it would certainly speed up implementation.
We still need to review and test (and sometimes cleanup/redesign) such patches as
SABnzbd is quite complex.

The Wiki should give you enough information on how to install Python and
the required modules.
Creating a binary distribution is tricky, but not needed if you have a working
Python environment (which you need anyway).
Compiling will not give you any speed or memory usage gains.
We'd rather not see other people distribute binary releases as this would be
confusing the to the users (and we would end up with the support questions).

Should you have time to spend on SABnzbd, have a look at the long wishlist here:
http://trac2.assembla.com/SABnzbd/report/3
decrypted
Newbie
Newbie
Posts: 11
Joined: September 2nd, 2008, 6:06 am

Re: Standby

Post by decrypted »

oki - as said in a Python environment the patch is running for me(tm).

Not sure if i can be helpfull in general as im not an expert in python. But will look at the list - http://trac2.assembla.com/SABnzbd/report/3.
I still admit the patch was fully selfish.


>Creating a binary distribution is tricky
I got quite far py2exe it was just missing modules. Stuff like elementtree - it didnt really accept the elementtree.pyd. Do you have dev mailing list or section in the forum for questions like that, to not spam the normal forum?
> but not needed
well more easy to run it as windows service then - but i will look into it thx.
Post Reply