wakepy icon indicating copy to clipboard operation
wakepy copied to clipboard

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

Open fohrloop opened this issue 1 year ago • 0 comments

As mentioned on https://github.com/fohrloop/wakepy/issues/60, there is a bug in the old implementation (wakepy/_deprecated/_windows.py). Since the SetThreadExecutionState changes "execution state" of current thread to either

  1. Prevent display power management
  2. Prevent suspend
  3. No prevented

if someone uses multiple wakelocks / activates multiple modes in a single thread, it will not work. For example this:

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

with keep.presenting():
    foo()
    bar()
  • Start with entering keep.presenting mode.
  • keep.presenting mode is active during baz()
  • This is overridden completely when entering keep.running mode, which is active during quux(). Only sleep is prevented, but display might turn off.
  • When the keep.running mode exits, the whole execution state is cleared with ES_CONTINUOUS
  • The bar() is being run without any mode active at all. System could go to sleep and display might turn off.

This bug has been there since the first version of wakepy.

Task

  • Make it possible to use two modes in same thread at same time.

fohrloop avatar Jan 19 '24 20:01 fohrloop