Giter VIP home page Giter VIP logo

Comments (15)

syyyr avatar syyyr commented on July 29, 2024 1

Thank you.

from py3status.

lasers avatar lasers commented on July 29, 2024

I googled a little. Can you confirm this issue still occur after you rebooted your system? I wonder if it's because the system gets updated and the machine eventually get suspended.

from py3status.

syyyr avatar syyyr commented on July 29, 2024

This issue appears even right after I reboot.

Oh and also: if I cancel the command and run it again, the bluetooth module starts works normally, so if I restart i3 with the restart shortcut, the problem goes away.

from py3status.

lasers avatar lasers commented on July 29, 2024

What do you mean by canceling the command and start again? Is that left or middle click? I think.

We can try adding this particular exception to see if it can be handled beautifully. Otherwise, there might be nothing we can do about it.

from py3status.

syyyr avatar syyyr commented on July 29, 2024

By cancelling the command I mean that I run py3status in the console for the output (just as a reproducer), then suspend, wake up, bluetooth doesn't work. After I interrupt the command, i.e. by pressing ctrl-c and start it up again, the bluetooth module works. For the actual i3bar, I have to restart the wm, which of course restarts py3status also, and makes the bluetooth module work fine.

from py3status.

syyyr avatar syyyr commented on July 29, 2024

The console reproducer works everytime. I do have a feeling that py3status in i3bar doesn't ALWAYS have this issue, but I'm not 100% sure. It seems to be some sort of a race condition.

from py3status.

lasers avatar lasers commented on July 29, 2024
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py
index 6d3711d..fc7ca15 100644
--- a/py3status/modules/bluetooth.py
+++ b/py3status/modules/bluetooth.py
@@ -123,7 +123,12 @@ class Py3status:
             )
 
     def _get_bluez_data(self):
-        objects = self.bluez_manager.GetManagedObjects()
+        try:
+            objects = self.bluez_manager.GetManagedObjects()
+        except Exception as e:
+            self.py3.log(type(e).__name__)
+            self.py3.log(e)
+
         temporary = {}
 
         for path, interfaces in sorted(objects.items()):

This will give you exception name / message.

We'll see if we can reinitialize the dbus connection and get a new client id... only on this exception.

EDIT: Try this one.

diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py
index 6d3711d..67bc3e0 100644
--- a/py3status/modules/bluetooth.py
+++ b/py3status/modules/bluetooth.py
@@ -105,12 +105,7 @@ class Py3status:
     thresholds = [(False, "bad"), (True, "good")]
 
     def post_config_hook(self):
-        bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
-        iface = "org.freedesktop.DBus.ObjectManager"
-        self.bluez_manager = Gio.DBusProxy.new_sync(
-            bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None
-        )
-
+        self._dbus_init()
         self.names_and_matches = [
             ("adapters", "org.bluez.Adapter1"),
             ("devices", "org.bluez.Device1"),
@@ -122,8 +117,24 @@ class Py3status:
                 getattr(self, name)
             )
 
+    def _dbus_init(self):
+        bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
+        iface = "org.freedesktop.DBus.ObjectManager"
+        self.bluez_manager = Gio.DBusProxy.new_sync(
+            bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None
+        )
+
     def _get_bluez_data(self):
-        objects = self.bluez_manager.GetManagedObjects()
+        try:
+            objects = self.bluez_manager.GetManagedObjects()
+        except Exception as e:
+            self.py3.log(type(e).__name__)
+            self.py3.log(e)
+
+            self.py3.log("Reinitializing D-Bus connection")
+            self._dbus_init()
+            objects = self.bluez_manager.GetManagedObjects()
+
         temporary = {}
 
         for path, interfaces in sorted(objects.items()):

from py3status.

syyyr avatar syyyr commented on July 29, 2024

Hi, sorry for not replying sooner - I tried your patch and it seems like it solves my problem.

from py3status.

lasers avatar lasers commented on July 29, 2024

I maybe would like to narrow this down to a particular exception. What does your log say?

from py3status.

syyyr avatar syyyr commented on July 29, 2024

This is the log with the patch applied

2023-11-28 13:41:50 INFO loading module "bluetooth" from py3status.modules.bluetooth
2023-11-28 13:41:50 INFO module "bluetooth" click_events=False has_kill=False methods=['bluetooth']
2023-11-28 13:41:50 INFO starting module bluetooth
2023-11-28 13:41:50 INFO method bluetooth returned {'composite': [{'full_text': 'BT: down', 'color': '#696969', 'instance': ' 0', 'name': 'bluetooth'}], 'instance': '', 'name': 'bluetooth'} 
2023-11-28 13:42:00 INFO method bluetooth returned {'composite': [{'full_text': 'BT: down', 'color': '#696969', 'instance': ' 0', 'name': 'bluetooth'}], 'instance': '', 'name': 'bluetooth'} 
-- SUSPENDED HERE --
2023-11-28 13:42:51 INFO Module `bluetooth`: Error
2023-11-28 13:42:51 INFO Module `bluetooth`: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.23330 was not provided by any .service files (2)
2023-11-28 13:42:51 INFO Module `bluetooth`: Reinitializing D-Bus connection
2023-11-28 13:42:51 INFO method bluetooth returned {'composite': [{'full_text': 'BT: down', 'color': '#696969', 'instance': ' 0', 'name': 'bluetooth'}], 'instance': '', 'name': 'bluetooth'} 

from py3status.

lasers avatar lasers commented on July 29, 2024

Cool. One more thing I'm wondering... I thought that modules would bounce back on next cache_timeout interval. Is that not happening for you? When you get back, you should see red bluetooth... for at least 10 seconds then it should try again... If not, I can put out a PR trying to address this.

from py3status.

syyyr avatar syyyr commented on July 29, 2024

cache_timeout works, but I get the error on every refresh. If I set it to 2, I get this error every 2 seconds:

2023-11-30 11:19:49 WARNING Instance `bluetooth`, user method `bluetooth` failed.
2023-11-30 11:19:49 INFO Traceback
Error: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.28474 was not provided by any .service files (2)
  File "/usr/lib/python3.11/site-packages/py3status/module.py", line 943, in run
    response = method()
               ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 146, in bluetooth
    bluez_data = self._get_bluez_data()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 124, in _get_bluez_data
    objects = self.bluez_manager.GetManagedObjects()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gi/overrides/Gio.py", line 349, in __call__
    result = self.dbus_proxy.call_sync(self.method_name, arg_variant,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This happens until I rerun py3status. Maybe it could be that the bluetooth module somehow saves the " :1.28474" name and suspending changes this name? Then, after reiniting py3status, it gets a new, correct name again. But tbh, I haven't looked at the code unfortunately.

from py3status.

lasers avatar lasers commented on July 29, 2024

Try this PR. Get some logs. I can't test this myself (obv). See if it catches your exception.

from py3status.

syyyr avatar syyyr commented on July 29, 2024

Thanks. I tried your PR and unfortunately, it doesnẗ fix the issue for me. Also I had to apply this patch, otherwise, the BT module wouldn't run:

diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py
index 146bd6c3..29d8dc12 100644
--- a/py3status/modules/bluetooth.py
+++ b/py3status/modules/bluetooth.py
@@ -89,7 +89,7 @@ SAMPLE OUTPUT
 {'color': '#00FF00', 'full_text': u'Microsoft Bluetooth Notebook Mouse 5000'}
 """
 
-from gi.repository import Gio, GLiB
+from gi.repository import Gio, GLib
 
 
 class Py3status:
@@ -115,7 +115,7 @@ class Py3status:
         for name in ["format", "format_adapter", "format_device"]:
             self.thresholds_init[name] = self.py3.get_color_names_list(getattr(self, name))
 
-    def _dbus_init():
+    def _dbus_init(self):
         bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
         iface = "org.freedesktop.DBus.ObjectManager"
         self.bluez_manager = Gio.DBusProxy.new_sync(
@@ -128,7 +128,7 @@ class Py3status:
             try:
                 objects = self.bluez_manager.GetManagedObjects()
                 self.py3.log(" --- SUCCESS ---")
-            except GLiB.Error as err:
+            except GLib.Error as err:
                 self.py3.log(" --- FAILED ---")
                 if err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.SERVICE_UNKNOWN):
                     self._dbus_init()

Maybe my python installation is missing something? I'm using Arch Linux. Anyway, after this, the code would run, but it doesn't fix the issue. This is the log from the bluetooth module:

2023-11-30 23:59:23 INFO starting module bluetooth
2023-11-30 23:59:23 INFO Module `bluetooth`:  --- RETRY 0 ---
2023-11-30 23:59:23 INFO Module `bluetooth`:  --- SUCCESS ---
2023-11-30 23:59:23 INFO method bluetooth returned {'composite': [{'full_text': 'BT: down', 'color': '#696969', 'instance': ' 0', 'name': 'bluetooth'}], 'instance': '', 'name': 'bluetooth'} 

... suspended here ...

2023-11-30 23:59:52 INFO Module `bluetooth`:  --- RETRY 0 ---
2023-11-30 23:59:52 INFO Module `bluetooth`:  --- FAILED ---
2023-11-30 23:59:52 WARNING Instance `bluetooth`, user method `bluetooth` failed.
2023-11-30 23:59:52 INFO Traceback
AttributeError: type object 'IOErrorEnum' has no attribute 'SERVICE_UNKNOWN'
  File "/usr/lib/python3.11/site-packages/py3status/module.py", line 943, in run
    response = method()
               ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 163, in bluetooth
    bluez_data = self._get_bluez_data()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 133, in _get_bluez_data
    if err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.SERVICE_UNKNOWN):
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 00:00:02 INFO Module `bluetooth`:  --- RETRY 0 ---
2023-12-01 00:00:02 INFO Module `bluetooth`:  --- FAILED ---
2023-12-01 00:00:02 WARNING Instance `bluetooth`, user method `bluetooth` failed.
2023-12-01 00:00:02 INFO Traceback
AttributeError: type object 'IOErrorEnum' has no attribute 'SERVICE_UNKNOWN'
  File "/usr/lib/python3.11/site-packages/py3status/module.py", line 943, in run
    response = method()
               ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 163, in bluetooth
    bluez_data = self._get_bluez_data()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/py3status/modules/bluetooth.py", line 133, in _get_bluez_data
    if err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.SERVICE_UNKNOWN):
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I guess the SERVICE_UNKNOWN code is somewhere else? I can't find it anywhere.

from py3status.

lasers avatar lasers commented on July 29, 2024

Your diff is right. I'm coding this blindly, thus untested.... I'm not sure how to catch this exception, but I found an example online... I lost the link, will look through my history. Also, https://lazka.github.io/pgi-docs/Gio-2.0/enums.html#Gio.DBusError.SERVICE_UNKNOWN

EDIT: Let's talk on PR #2221.

from py3status.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.