Skip to content

Commit e31b21e

Browse files
committed
Use glib's native asyncio integration when available
Glib >= 3.50 has native asyncio integration. When available, use it instead of gbulb. This requires few minor changes: - asyncio.run() doesn't work there (asyncio.set_event_loop() cannot be called on the main thread with glib...) QubesOS/qubes-issues#9809
1 parent 6124fa0 commit e31b21e

File tree

8 files changed

+49
-16
lines changed

8 files changed

+49
-16
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Build-Depends:
66
debhelper (>= 9),
77
dh-python,
88
python3-all,
9-
python3-gbulb,
9+
python3-gi (>= 3.50.0) | python3-gbulb,
1010
python3-setuptools,
1111
python3-systemd,
1212
Standards-Version: 3.9.5

qui/clipboard.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@
4545
gi.require_version("Gtk", "3.0") # isort:skip
4646
from gi.repository import Gtk, Gio, Gdk # isort:skip
4747

48-
import gbulb
48+
try:
49+
from gi.events import GLibEventLoopPolicy
50+
51+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
52+
except ImportError:
53+
import gbulb
54+
55+
gbulb.install()
56+
4957
import pyinotify
5058

5159
import gettext
@@ -55,8 +63,6 @@
5563

5664
from .utils import run_asyncio_and_show_errors
5765

58-
gbulb.install()
59-
6066
DATA = "/var/run/qubes/qubes-clipboard.bin"
6167
METADATA = "/var/run/qubes/qubes-clipboard.bin.metadata"
6268
FROM = "/var/run/qubes/qubes-clipboard.bin.source"

qui/devices/device_widget.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,20 @@
4444
gi.require_version("Gtk", "3.0") # isort:skip
4545
from gi.repository import Gtk, Gdk, Gio # isort:skip
4646

47+
try:
48+
from gi.events import GLibEventLoopPolicy
49+
50+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
51+
except ImportError:
52+
import gbulb
53+
54+
gbulb.install()
55+
4756
from qui.devices import backend
4857
from qui.devices import actionable_widgets
4958

5059
from qubes_config.widgets.gtk_utils import is_theme_light
5160

52-
import gbulb
53-
54-
gbulb.install()
55-
5661
import gettext
5762

5863
t = gettext.translation("desktop-linux-manager", fallback=True)

qui/tools/qubes_device_agent.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636
# pylint: enable=import-error
3737

3838
# pylint: disable=wrong-import-order
39-
import gbulb
39+
try:
40+
from gi.events import GLibEventLoopPolicy
41+
42+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
43+
except ImportError:
44+
import gbulb
45+
46+
gbulb.install()
4047

4148
# pylint: enable=wrong-import-position
4249

@@ -256,10 +263,10 @@ async def handle_request(self, params, service, source_domain):
256263
def main():
257264
args = parser.parse_args()
258265

259-
gbulb.install()
260266
agent = DeviceAgent(args.socket_path)
261267

262-
asyncio.run(agent.run())
268+
loop = asyncio.get_event_loop()
269+
loop.run_until_complete(agent.run())
263270

264271

265272
if __name__ == "__main__":

qui/tray/domains.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@
2626
gi.require_version("Gtk", "3.0") # isort:skip
2727
from gi.repository import Gdk, Gio, Gtk, GLib, GdkPixbuf # isort:skip
2828

29-
import gbulb
29+
try:
30+
from gi.events import GLibEventLoopPolicy
3031

31-
gbulb.install()
32+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
33+
except ImportError:
34+
import gbulb
35+
36+
gbulb.install()
3237

3338
import gettext
3439

qui/tray/updates.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
gi.require_version("Gtk", "3.0") # isort:skip
2424
from gi.repository import Gtk, Gio # isort:skip
2525

26-
import gbulb
26+
try:
27+
from gi.events import GLibEventLoopPolicy
2728

28-
gbulb.install()
29+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
30+
except ImportError:
31+
import gbulb
32+
33+
gbulb.install()
2934

3035
import gettext
3136

qui/updater/summary_page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ def shutdown_domains(self, to_shutdown):
338338
)
339339
self.status = RestartStatus.ERROR_TMPL_DOWN
340340

341-
asyncio.run(wait_for_domain_shutdown(wait_for))
341+
loop = asyncio.get_event_loop()
342+
loop.run_until_complete(wait_for_domain_shutdown(wait_for))
342343

343344
return wait_for
344345

rpm_spec/qubes-desktop-linux-manager.spec.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ BuildRequires: python%{python3_pkgversion}-setuptools
4848
BuildRequires: gettext
4949

5050
Requires: python%{python3_pkgversion}-setuptools
51+
%if 0%{?fedora} < 42
5152
Requires: python%{python3_pkgversion}-gbulb
53+
%else
54+
Requires: python%{python3_pkgversion}-gobject >= 3.50.0
55+
%endif
5256
Requires: python%{python3_pkgversion}-inotify
5357
Requires: libappindicator-gtk3
5458
Requires: python%{python3_pkgversion}-systemd

0 commit comments

Comments
 (0)