SKD
SKD

Reputation: 43

How to make ubuntu OS to get sleep using python?

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 ?

Upvotes: 0

Views: 406

Answers (1)

Daan Klijn
Daan Klijn

Reputation: 1694

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.

Upvotes: 1

Related Questions