minarca
minarca copied to clipboard
wakepy linux & mac support
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.
@np-8 Thanks for keep track of this.
I will take a look at it soon and test your suggestion.
Thanks !
@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'
@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.
@np-8 Thanks for helping.
This occur in Docker container. Systemd is not running in a container.
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 https://github.com/np-8/wakepy/issues/26.