Skip to content

Fix: Isolate SetThreadExecutionState modes on same thread from each other#342

Merged
fohrloop merged 22 commits into
mainfrom
issue-167-windows-multiple-modes-same-thread
Jun 2, 2024
Merged

Fix: Isolate SetThreadExecutionState modes on same thread from each other#342
fohrloop merged 22 commits into
mainfrom
issue-167-windows-multiple-modes-same-thread

Conversation

@fohrloop
Copy link
Copy Markdown
Member

@fohrloop fohrloop commented Jun 2, 2024

Fixes: #167

The SetThreadExecutionState Method may now have multiple modes (same or different) activated within the same python thread without them interfering with each other on activation or deactivation, as wakepy creates a separate worker thread for the single purpose of setting and keeping the thread execution flag each time you activate a mode with the SetThreadExecutionState wakepy.Method.

Before this PR

Running

from wakepy import keep
import time 

def foo():
   with keep.running():
       ...

with keep.presenting():
    foo()
    time.sleep(1000)

produced no lock holders (Expected: DISPLAY and SYSTEM):

PS C:\Users\niko> powercfg /requests
DISPLAY:
None.

SYSTEM:
None.

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

After this PR

Running

from wakepy import keep
import time 

def foo():
   with keep.running():
       ...

with keep.presenting():
    foo()
    time.sleep(1000)

produces (as expected)

PS C:\Users\niko> powercfg /requests
DISPLAY:
[PROCESS] \Device\HarddiskVolume3\Python310\python.exe

SYSTEM:
[PROCESS] \Device\HarddiskVolume3\Python310\python.exe

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

(DISPLAY and SYSTEM kept awake as expected), and running

def foo():
   with keep.presenting():
       ...

with keep.running():
    foo()
    time.sleep(1000)

produces:

PS C:\Users\niko> powercfg /requests
DISPLAY:
None.

SYSTEM:
[PROCESS] \Device\HarddiskVolume3\Python310\python.exe

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

ACTIVELOCKSCREEN:
None.

(only SYSTEM kept awake as expected)

@fohrloop fohrloop changed the title Issue 167 windows multiple modes same thread Fix: Isolate SetThreadExecutionState modes on same thread from each other Jun 2, 2024
@fohrloop fohrloop merged commit 0d907f7 into main Jun 2, 2024
@fohrloop fohrloop deleted the issue-167-windows-multiple-modes-same-thread branch June 4, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Windows/SetThreadExecutionState based modes on same thread are not isolated from each other

1 participant