-
Notifications
You must be signed in to change notification settings - Fork 13
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
Import failing when DBUS_SESSION_BUS_ADDRESS not available #35
Comments
Hi @rileyyy and thanks for the information! If I understood correctly, there are two problems: import time exceptions and failure of detecting dbus. Problem 1: import time exceptionsI am kind of aware of this problem, and working on a fix. I opened #26 when I found out that importing wakepy will fail in any tox tests if from wakepy import keepawake
with keepawake(on_failure='warn'):
# do something After this is ready Problem 2: not detecting dbusIf I have understood correctly, dbus works like this:
I am no means yet an expert of the subject, though. There are also some other ways the session bus address can be advertised. From DBus Specification:
Currently, I am using jeepney to get the dbus session address. The implementation in jeepney for getting the session bus address is: def find_session_bus():
addr = os.environ['DBUS_SESSION_BUS_ADDRESS']
return next(get_connectable_addresses(addr))
# TODO: fallbacks to X, filesystem So it only checks the best guess, environment variable Possible solutions for problem 2Option A
Option B
worked for me. It should be pretty easy to do this in python, at least if it would simply use subprocess to call Option C
Option D
Any thoughts on the options? Or do you have some other suggestions or comments? How did you start |
Wow thanks for the comprehensive response! I must have skipped over #26 since it seems you're pretty aware of this. I'm afraid I'm not very familiar with dbus or I might have realized what was going on there better. Presently, I've wrapped the import with a try/except for the KeyError so we could get a release out. But after talking to another developer I work with, we aren't too concerned as Linux users are probably an incredibly small userbase. I'm afraid I'm out of the office until monday so I can't check the ps -x output until next week. I can certainly fine with closing this as duplicate since you seem aware of the problem. But I can certainly try to help figure out a work around for what I may be able to provide haha. |
For problem 1, this can be considered as duplicate, but if you think that dbus should be detected even when I somehow did not register that you were running wakepy on WSL. I have not even considered how it should work there. In particular, I'm not sure how we systemd and dbus are working on WSL, and/or if those still could be used to prevent suspend of Windows. I made separate issue for WSL support: #36 |
Just wanted to update with some results if that helps at all for the WSL related support.
|
Hi @rileyyy and thanks for the update! I hope I'll have some spare in the coming weeks so I could work on the next release and get at least the import-time exception fixed or more helpful. |
This one is fixed. on_fail behaviourThe default behaviour in 0.8.0dev (unreleased, available in the from wakepy import keep
import os
del os.environ['DBUS_SESSION_BUS_ADDRESS']
with keep.running():
... This will show:
This can be also changed to a warning: with keep.running(on_fail='warn'):
... and it's possible to use any callable which takes in an ActivationResult: def do_something(result: ActivationResult):
...
with keep.running(on_fail=do_something):
... wakepy in tests -> WAKEPY_FAKE_SUCCESSIn tests and continuous integration, one can set WAKEPY_FAKE_SUCCESS to a truthy value, which will skip using any real methods (and io) and fake a success: >>> os.environ['WAKEPY_FAKE_SUCCESS'] = '1'
>>> with keep.running() as m:
print(m.active)
True
>>> m.activation_result.active_method
'WAKEPY_FAKE_SUCCESS' WSL supportThis one is under development and continuing in issue 36. |
Hej,
The issue originally stems from another project where I am importing wakepy and it is causing all sorts of issues in readthedocs generation. I was able to reproduce the issue locally though with just wakepy.
Presently running an Ubuntu 20.04.4 LTS VM on WSL.
While I did get dbus-x11 installed and running, it seems $DBUS_SESSION_BUS_ADDRESS isn't set and that is causing problems.
I'm not sure what else is missing but maybe it could be caught by expanding the except after the
import dbus
The text was updated successfully, but these errors were encountered: