How to make ubuntu OS to get sleep using python?

309 views Asked by At

using python coding i want to make make the system to get sleep state , is that possible ? i need the solution in Ubuntu , i can find that for windows but for Ubuntu is their any solution ?

1

There are 1 answers

0
Daan Klijn On BEST ANSWER

Using os.system you can call terminal commands. You can for instance use systemctl hibernate to get Ubuntu to sleep.

import os
os.system("systemctl hibernate")

Note: you might need to run your python file using sudo.