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

wakepy linux & mac support #12

Closed
fohrloop opened this issue Mar 19, 2023 · 5 comments
Closed

wakepy linux & mac support #12

fohrloop opened this issue Mar 19, 2023 · 5 comments

Comments

@fohrloop
Copy link

Hi,

I'm the maintainer of the wakepy package, and was just looking where the package is used. I noticed that you install wakepy on all systems, but utilize it only on Windows. I'm guessing the reason for that might be that at the time when minarca-client/minarca_client/core/__init__.py near set_keepawake was changed (Aug 30, 2021), the mac version had a bug and linux version needed sudo (wakepy 0.4.3). The wakepy 0.6.0 has the mac bug fixed and linux version works without sudo (using dbus instead of systemd).

So, this:

# minarca-client/minarca_client/core/__init__.py
        try:
            if IS_WINDOWS:
                from wakepy import set_keepawake

                set_keepawake(keep_screen_awake=False)
        except Exception:
            pass

could be

# minarca-client/minarca_client/core/__init__.py
        try:
            from wakepy import set_keepawake
            set_keepawake(keep_screen_awake=False)
        except NotImplementedError:
            pass

(+ similar handling with unset_keepawake). That would then ensure also on linux/mac that system will not suspend/sleep in the middle of processing.

@ikus060
Copy link
Owner

ikus060 commented Mar 19, 2023

@np-8 Thanks for keep track of this.

I will take a look at it soon and test your suggestion.

Thanks !

@ikus060
Copy link
Owner

ikus060 commented Mar 23, 2023

@np-8
I started testing on Linux and calling wakepy is failing as follow if the system is not running a DBus.

minarca_client/ui/tests/test_status.py:13: in <module>
    from minarca_client.core.compat import IS_LINUX
minarca_client/core/__init__.py:28: in <module>
    from wakepy import set_keepawake, unset_keepawake
.tox/py3-linux/lib/python3.7/site-packages/wakepy/__init__.py:35: in <module>
    from ._linux import set_keepawake, unset_keepawake
.tox/py3-linux/lib/python3.7/site-packages/wakepy/_linux/__init__.py:17: in <module>
    my_module = import_module(f".{module}", f"wakepy._linux")
/usr/local/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
.tox/py3-linux/lib/python3.7/site-packages/wakepy/_linux/_jeepney_dbus.py:26: in <module>
    connection = open_dbus_connection(bus="SESSION")
.tox/py3-linux/lib/python3.7/site-packages/jeepney/io/blocking.py:341: in open_dbus_connection
    bus_addr = get_bus(bus)
.tox/py3-linux/lib/python3.7/site-packages/jeepney/bus.py:53: in get_bus
    return find_session_bus()
.tox/py3-linux/lib/python3.7/site-packages/jeepney/bus.py:42: in find_session_bus
    addr = os.environ['DBUS_SESSION_BUS_ADDRESS']
/usr/local/lib/python3.7/os.py:681: in __getitem__
    raise KeyError(key) from None
E   KeyError: 'DBUS_SESSION_BUS_ADDRESS'

@fohrloop
Copy link
Author

@ikus060 Thank you this is really valuable! As this occurs import time this should really be changed to ImportError! I will publish a patch for this!

By the way, what system you were using for the test? When there is no dbus, it should fall back to systemd, which should then fail (with ImportError but I have to check it) if not running with sudo.

@ikus060
Copy link
Owner

ikus060 commented Mar 23, 2023

@np-8 Thanks for helping.

This occur in Docker container. Systemd is not running in a container.

@fohrloop
Copy link
Author

fohrloop commented Apr 6, 2023

Just wanted to give a brief update that I've finally got some extra time to work on this. I decided to also add some basic testing to wakepy, and got similar error message when importing wakepy in pytest in tox. I'm not even using a docker container. I'm documenting my findings to fohrloop/wakepy#26.

@ikus060 ikus060 closed this as completed Jun 14, 2024
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