Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still going to sleep - running Fedora 36 #18

Closed
noelgarber opened this issue Oct 5, 2022 · 7 comments
Closed

Still going to sleep - running Fedora 36 #18

noelgarber opened this issue Oct 5, 2022 · 7 comments
Milestone

Comments

@noelgarber
Copy link

noelgarber commented Oct 5, 2022

I'm running Fedora 36 on a Lenovo Legion 7, and I ran the simple code:

from wakepy import set_keepawake, unset_keepawake
set_keepawake()

Yet my computer still goes to sleep after a few minutes. What's happening?

@fohrloop
Copy link
Owner

fohrloop commented Oct 5, 2022

Hi @noelgarber and thanks for filing the issue!

I think we could check a two things here:

1) systemctl

  • As mentioned in the docs, wakepy uses systemctl mask to prevent computer going to sleep, when used on Linux. Does your system have systemd? If yes, try to run
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

and see if that prevents your computer from going to sleep or not

2) privileges

The systemctl command needs sudo privileges. Because current version of wakepy uses systemctl, it needs sudo. Did you run you script with sudo privileges?

@noelgarber
Copy link
Author

Thanks for the reply! Here are the answers:

  1. Yes, I do have systemd (as verified by ps -p 1 -o comm=), and no, that command does not prevent my computer from going to sleep - it goes to sleep after 5 minutes even after running that. Here is what came up in terminal:

[ngarber@legion7 ~]$ systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.

After typing the command, it prompts for a password before executing, which I entered. Same behaviour as when I run set_keepawake() from wakepy.

  1. It asks for a password when I run set_keepawake() from wakepy, so I assume entering the password gives the necessary permissions.

Unfortunately, when I run sudo python3 and then try to run from wakepy import set_keepawake, unset keepawake, it returns ModuleNotFoundError: No module named 'wakepy'. Somehow, when running inside sudo, Python can't find wakepy despite it being installed on my computer...

@fohrloop
Copy link
Owner

fohrloop commented Feb 9, 2023

Hi and sorry for long delay!

For part 2, I think it is because sudo has different set of environment variables than your user, and wakepy is installed to a folder which is added (only) to the PATH of your current user. See, for example: How to make sudo preserve $PATH?. Based on that I guess that

sudo env "PATH=$PATH" python3

would preserve your PATH with sudo.

@fohrloop
Copy link
Owner

fohrloop commented Feb 9, 2023

For part 1, I found a least this answer which has a comment which says that commands like

sudo systemctl mask suspend.target
sudo systemctl mask sleep.target

would not work on Fedora. I tried to search for a solution for Google but could not find much of anything useful. One solution at ask.fedoraproject.org/ adviced to install xset and run

xset s off

Looking at wiki.archlinux.org it seems that the command is merely "Disable screen saver blanking", and

xset s off -dpms

would be "Disable DPMS and prevent screen from blanking", where DPMS = Display Power Management Signaling. Not sure if that only applies to the display, though. At the same page it also mentions setterm.

Let me hear if you (or anyone else) found a solution for Fedora :)

@fohrloop
Copy link
Owner

@noelgarber I just published wakepy 0.6.0 and it has two options of using DBus + inhibit method. I suppose this will fix also your problems on Fedora!

@fohrloop fohrloop added this to the wakepy 0.8.0 milestone Oct 29, 2023
@fohrloop
Copy link
Owner

I haven't checked if this is fixed yet but added 0.8.0 milestone, as Fedora (Workstation 36) uses GNOME 42, and support for GNOME using org.gnome.SessionManager (D-Bus) is in the list of changes for 0.8.0.

@fohrloop
Copy link
Owner

Just installed Fedora 36 for testing purposes. Running with the latest dev version:

In [1]: import wakepy

In [2]: wakepy.__version__
Out[2]: '0.8.0dev'

In [3]: from wakepy import keep

In [4]: import time
   ...: with keep.running() as m:
   ...:     print(m.active)
   ...:     print(m.activation_result.active_method)
   ...:     time.sleep(2000)

Confirming that the org.gnome.SessionManager based keep.running & keep.presenting methods and the org.freedesktop.ScreenSaver based keep.presenting method work well on Fedora 36 with GNOME 42.0, using the latest 0.8.0dev.

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

No branches or pull requests

2 participants