Esempio n. 1
0
    def test_sleepless_not_there(self):
        assert not self.check_msg_in_assertions()
        assert sleepless.assertion_id is None

        sleepless.allow_sleep()
        assert not self.check_msg_in_assertions()
        assert sleepless.assertion_id is None
Esempio n. 2
0
    def test_sleepless_multi_call(self):
        # If we set it twice, is it still cleared with one call
        assert not self.check_msg_in_assertions()
        assert sleepless.assertion_id is None

        sleepless.keep_awake(self.sleep_msg)
        time.sleep(2)
        sleepless.keep_awake(self.sleep_msg)
        assert self.check_msg_in_assertions()

        sleepless.allow_sleep()
        assert not self.check_msg_in_assertions()
        assert sleepless.assertion_id is None
Esempio n. 3
0
    def test_sleepless(self):
        # Run twice to see if it keeps going well
        for _ in range(2):
            # Keep it awake
            sleepless.keep_awake(self.sleep_msg)
            time.sleep(2)

            # Check if it's still in the assertions list
            assert self.check_msg_in_assertions()

            # Remove and see if it's still there
            sleepless.allow_sleep()
            assert not self.check_msg_in_assertions()
            assert sleepless.assertion_id is None
Esempio n. 4
0
def keep_awake():
    """ If we still have work to do, keep Windows/OSX system awake """
    if KERNEL32 or FOUNDATION:
        if sabnzbd.cfg.keep_awake():
            ES_CONTINUOUS = 0x80000000
            ES_SYSTEM_REQUIRED = 0x00000001
            if (not Downloader.do.is_paused() and not NzbQueue.do.is_empty()) or (
                not PostProcessor.do.paused and not PostProcessor.do.empty()
            ):
                if KERNEL32:
                    # Set ES_SYSTEM_REQUIRED until the next call
                    KERNEL32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
                else:
                    sleepless.keep_awake("SABnzbd is busy downloading and/or post-processing")
            else:
                if KERNEL32:
                    # Allow the regular state again
                    KERNEL32.SetThreadExecutionState(ES_CONTINUOUS)
                else:
                    sleepless.allow_sleep()