2

I want to find out if I can launch a function or a method in a python program right before the computer sleep, something that goes along the line of

def f():
    if about_to_sleep:
        do_stuff
    else:
        do_some_other_stuff

that can work in windows 10

user208685
  • 111
  • 1
  • 9

2 Answers2

2

If you didn't mind writing a small C++ application to run in the background, it could call your python script when it detects the computer going into sleep.

Take a look at: Qt detect when computer goes into sleep?

Community
  • 1
  • 1
theSparky
  • 280
  • 2
  • 9
0

Detecting computer/program shutdown in Python?

This was a question similar to yours, but might still be relevant.

Community
  • 1
  • 1
coder188642
  • 149
  • 2
  • 5
  • 15