caffeine-ng icon indicating copy to clipboard operation
caffeine-ng copied to clipboard

Python 3.9.5 may have broken caffeine.

Open GeorgiKarapetrov opened this issue 4 years ago • 11 comments

OS: Arch Linux Kernel ver: 5.12.1-zen2-1-zen Bash ver: 5.1.8 Python ver: 3.9.5 Caffeine-ng ver: 3.5.1

A recent update broke the caffeine workflow. Possibly it is Python 3.9.5. It could have happened earlier though if I missed the issue.

Output of caffeine -a:

/usr/lib/python3.9/site-packages/caffeine/main.py:61: PyGIWarning: AppIndicator3 was imported without specifying a version first. Use gi.require_version('AppIndicator3', '0.1') before import to ensure that the right version gets loaded.
  from gi.repository import AppIndicator3
Traceback (most recent call last):
  File "/usr/bin/caffeine", line 33, in <module>
    sys.exit(load_entry_point('caffeine-ng==3.5.1', 'gui_scripts', 'caffeine')())
  File "/usr/lib/python3.9/site-packages/caffeine/main.py", line 454, in main
    main = GUI(arguments["--preferences"])
  File "/usr/lib/python3.9/site-packages/caffeine/main.py", line 155, in __init__
    self.__core = Caffeine(self.__process_manager)
  File "/usr/lib/python3.9/site-packages/caffeine/core.py", line 82, in __init__
    self._ewmh = EWMH()
  File "/usr/lib/python3.9/site-packages/ewmh/ewmh.py", line 70, in __init__
    self.display = _display or display.Display()
  File "/usr/lib/python3.9/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/lib/python3.9/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/usr/lib/python3.9/site-packages/Xlib/protocol/display.py", line 166, in __init__
    raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":1": b'Invalid MIT-MAGIC-COOKIE-1 key'

Please, let me know if I can assist you with some debug log.

GeorgiKarapetrov avatar May 13 '21 13:05 GeorgiKarapetrov

Are you using KDE? This kinda looks like #51, though I'm not sure what's causing that one either :disappointed:

This doen't look related to the Python version though.

WhyNotHugo avatar May 13 '21 14:05 WhyNotHugo

Sorry, it's hard for me to tell.

I am using BSPWM ver. 0.9.10 and Xorg ver. 1.20.11

Caffeine was working fine until recently. I suspect an Arch Linux system update broke it though its hard for me to analyze the reason.

Can I help you with the output of some command?

Workaround: Make a cron job

* * * * * DISPLAY=:1 xdotool key Num_Lock && DISPLAY=:1 xdotool key Num_Lock

#51 doesn't seem to have a resolution.

GeorgiKarapetrov avatar May 13 '21 15:05 GeorgiKarapetrov

Same issue in gentoo.

2021-07-02_17-02

HougeLangley avatar Jul 02 '21 09:07 HougeLangley

Maybe it's time to drop python 3.5.1

HougeLangley avatar Jul 02 '21 09:07 HougeLangley

@HougeLangley That error message you pasted says something completely different.

Looks like you need to install python-ewmh.

WhyNotHugo avatar Jul 05 '21 18:07 WhyNotHugo

I have the same issue with arch and the i3. I'm not super familiar with the X environment. And the workaround @GeorgiKarapetrov doesn't work for me.

Larusso avatar Sep 21 '21 09:09 Larusso

I believe I am having an extension of this issue for Python 3.10, but I'm not sure. Please let me know if I should open a new issue. I had a lot of python updates today, and after rebooting Caffeine didn't start (error info below)

System Details: OS: Arch Linux x86_64 Host: Latitude E7470 Kernel: 5.15.7-zen1-1-zen Uptime: 2 hours, 40 mins Packages: 1314 (pacman), 4 (flatpak) Shell: bash 5.1.12 Resolution: 1920x1080, 1920x1080 DE: Xfce 4.16 WM: Xfwm4 WM Theme: Adapta-DeepOrange-Nokto Theme: Adapta-DeepOrange-Nokto-Eta [GTK2/3] Icons: ePapirus-Dark [GTK2/3] Terminal: xfce4-terminal Terminal Font: Source Code Pro 12 CPU: Intel i7-6600U (4) @ 3.400GHz GPU: Intel Skylake GT2 [HD Graphics 520] Memory: 3327MiB / 31996MiB

Python Version: 3.10.1-1 Caffeine-NG Version: 3.5.1-2

I think it's also relevant that I'm running pipewire instead of pulseaudio pipewire version: 1:0.3.41-1

Error Details (when running 'caffeine' from terminal):

Traceback (most recent call last): File "/usr/bin/caffeine", line 33, in sys.exit(load_entry_point('caffeine-ng==3.5.1', 'gui_scripts', 'caffeine')()) File "/usr/bin/caffeine", line 25, in importlib_load_entry_point return next(matches).load() File "/usr/lib/python3.10/importlib/metadata/init.py", line 162, in load module = import_module(match.group('module')) File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/lib/python3.10/site-packages/caffeine/main.py", line 54, in from .core import Caffeine # noqa: E402 File "/usr/lib/python3.10/site-packages/caffeine/core.py", line 26, in from pulsectl import Pulse ModuleNotFoundError: No module named 'pulsectl'

etuckeriv avatar Dec 13 '21 19:12 etuckeriv

I too have started having issues with Caffeine-ng on Arch. Only in the last day or so since there were some Python updates.

OS: Arch Linux x86_64 
Host: VMware7,1 None 
Kernel: 5.15.7-arch1-1 
Uptime: 39 mins 
Packages: 1790 (pacman), 6 (flatpak) 
Shell: zsh 5.8 
Resolution: 5120x2880 
DE: GNOME 41.2 
WM: Mutter 
WM Theme: Adwaita 
Theme: Adwaita-dark [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Terminal: terminator 
CPU: Intel i9-9980HK (8) @ 2.400GHz 
GPU: 00:0f.0 VMware SVGA II Adapter 
Memory: 2091MiB / 32071MiB

Python: 3.10.1
Caffeine-ng: 3.5.1
Traceback (most recent call last):
  File "/bin/caffeine", line 33, in <module>
    sys.exit(load_entry_point('caffeine-ng==3.5.1.post71+g77611ac', 'gui_scripts', 'caffeine')())
  File "/bin/caffeine", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 162, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/caffeine/cli.py", line 9, in <module>
    from caffeine.main import GUI
  File "/usr/lib/python3.10/site-packages/caffeine/main.py", line 38, in <module>
    from caffeine.core import Caffeine  # noqa: E402
  File "/usr/lib/python3.10/site-packages/caffeine/core.py", line 38, in <module>
    from caffeine.triggers import DesiredState
  File "/usr/lib/python3.10/site-packages/caffeine/triggers.py", line 8, in <module>
    from pulsectl import Pulse
ModuleNotFoundError: No module named 'pulsectl'

I have tried re-installing Caffeine-ng from the AUR and also tried the "-git" version. Both fail to start unfortunately.

fsociety3765 avatar Dec 15 '21 12:12 fsociety3765

@etuckeriv @fsociety3765: https://aur.archlinux.org/packages/caffeine-ng/#comment-840748

After upgrading to Python 3.10, you need to rebuild all Python packages built with Python 3.9. You can get a list of these packages using:

pacman -Qo /usr/lib/python3.9

You can reinstall these with:

paru -S --aur --rebuild $(pacman -Qo /usr/lib/python3.9)

WhyNotHugo avatar Dec 15 '21 12:12 WhyNotHugo

I got the same error on NixOS KDE, and don't know if it is related to the build system or else.

What I have also tried:

  • Build the package against python 3.7, 3.8, 3.9 and 3.10, and the issue persists
  • Install Nix into different OS's and build+run the package. Gnome based distros seem to run OK, while KDE based (OpenSUSE) gives the same error.

If you want to replicate the error for the Nix build, I have included instruccions here: https://github.com/viperML/dotfiles/tree/master/overlay/caffeine-ng

Error log
$ /nix/store/9yz24nqx4v3aawlr4z0knbms27qqh6cd-caffeine-ng-3.5.1/bin/caffeine
Traceback (most recent call last):
  File "/nix/store/9yz24nqx4v3aawlr4z0knbms27qqh6cd-caffeine-ng-3.5.1/bin/..caffeine-wrapped-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/9yz24nqx4v3aawlr4z0knbms27qqh6cd-caffeine-ng-3.5.1/lib/python3.9/site-packages/caffeine/main.py", line 454, in main
    main = GUI(arguments["--preferences"])
  File "/nix/store/9yz24nqx4v3aawlr4z0knbms27qqh6cd-caffeine-ng-3.5.1/lib/python3.9/site-packages/caffeine/main.py", line 155, in __init__
    self.__core = Caffeine(self.__process_manager)
  File "/nix/store/9yz24nqx4v3aawlr4z0knbms27qqh6cd-caffeine-ng-3.5.1/lib/python3.9/site-packages/caffeine/core.py", line 82, in __init__
    self._ewmh = EWMH()
  File "/nix/store/89s83qq496mp9fj1c3sx2a08saw6m3ry-python3.9-ewmh-0.1.6/lib/python3.9/site-packages/ewmh/ewmh.py", line 70, in __init__
    self.display = _display or display.Display()
  File "/nix/store/20pbs2igjyb58655nd9cj27zrski0a49-python3.9-xlib-0.29/lib/python3.9/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/nix/store/20pbs2igjyb58655nd9cj27zrski0a49-python3.9-xlib-0.29/lib/python3.9/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/nix/store/20pbs2igjyb58655nd9cj27zrski0a49-python3.9-xlib-0.29/lib/python3.9/site-packages/Xlib/protocol/display.py", line 166, in __init__
    raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n'

viperML avatar Jan 19 '22 14:01 viperML

From what I have investigated, it seems that a different environment in KDE causes a bug in python-xlib:

https://github.com/python-xlib/python-xlib/issues/207#issuecomment-905194636

The mentioned patch to xlib seems to solve the issue:

--- a/Xlib/xauth.py
+++ b/Xlib/xauth.py
@@ -118,7 +118,7 @@ class Xauthority(object):
         matches = {}
 
         for efam, eaddr, enum, ename, edata in self.entries:
-            if efam == family and eaddr == address and num == enum:
+            if efam == family and eaddr == address:
                 matches[ename] = edata
 
         for t in types:

viperML avatar Jan 19 '22 18:01 viperML

This project has moved to codeberg.

Follow-up for this issue is at https://codeberg.org/WhyNotHugo/caffeine-ng/issues/66

WhyNotHugo avatar Nov 06 '22 14:11 WhyNotHugo