Git Product home page Git Product logo

Comments (6)

JonLevin25 avatar JonLevin25 commented on July 17, 2024 1

Np :)
If I ever test on linux I'll be sure to update here as well.

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

Hi @JonLevin25, glad that you like it!

On the linux & mac versions, I have say honestly that I don't know, and would refer to the documentation of the underlying apps that keep the process awake (_linux.py and _darwin.py).

On Windows, I would actually very much guess that the behaviour is the opposite of what you've suggested. As you have read, in _win.py the SetThreadExecutionState is called, which in my understanding kind of sets a flag for the operating system to not start sleeping:

ES_CONTINUOUS
0x80000000
Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.

This also means that in practice one could, with current implementation, accidentally remove this flag with some other process/thread (even outside of python).

I fully agree that some sort of table in the docs would be handy! :)

from wakepy.

JonLevin25 avatar JonLevin25 commented on July 17, 2024

About windows - I thought the same thing at first.
But the name suggests SetThreadExecutionState is local to the current Thread. (which should die with the process)

I've tested this and it is indeed reset:

import wakepy
wakepy.set_keepawake()
while True:
    pass

(In admin terminal)

PS C:\Users\Jon> powercfg -requests
DISPLAY:
None.

SYSTEM:
[PROCESS] ...\AppData\Local\Programs\Python\Python310\python.exe

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

After killing the process (from PyCharm or Task Manager)

PS C:\Users\Jon> powercfg -requests
DISPLAY:
None.

SYSTEM:
None.

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

Hi @JonLevin25,

Oh wow, thanks for the info! You're right! Nice catch 😎

The execution state flag is really tied to the process. I tested by using threading.Threads, and whenever a thread is done executing and dies, the flag disappears from powercfg -requests listing. Also, it is possible to have multiple threads (& processes) having flags of their own; all of the processes must either remove their flags or die before windows would go into sleep. See, for example here, there are two processes calling wakepy.set_keepawake, with the second one also having keep_screen_awake=True:

PS C:\WINDOWS\system32>  powercfg -requests
DISPLAY:
[PROCESS] \Device\HarddiskVolume3\Python\Python385-64\python.exe

SYSTEM:
[PROCESS] \Device\HarddiskVolume3\Python\Python385-64\python.exe
[PROCESS] \Device\HarddiskVolume3\Python\Python385-64\python.exe

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

Nice! I also added a Summary table to the README.md.

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

This is now documented for Windows and Linux. Created new ticket (#25) for macOS so this one can be closed. Thanks @JonLevin25 for your contribution !

from wakepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.