Skip to content

Commit dd1471d

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 dd1471d

File tree

8 files changed

+40
-17
lines changed

8 files changed

+40
-17
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
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+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
51+
except ImportError:
52+
import gbulb
53+
gbulb.install()
54+
4955
import pyinotify
5056

5157
import gettext
@@ -55,8 +61,6 @@
5561

5662
from .utils import run_asyncio_and_show_errors
5763

58-
gbulb.install()
59-
6064
DATA = "/var/run/qubes/qubes-clipboard.bin"
6165
METADATA = "/var/run/qubes/qubes-clipboard.bin.metadata"
6266
FROM = "/var/run/qubes/qubes-clipboard.bin.source"

qui/devices/device_widget.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
4949

5050
from qubes_config.widgets.gtk_utils import is_theme_light
5151

52-
import gbulb
53-
54-
gbulb.install()
52+
try:
53+
from gi.events import GLibEventLoopPolicy
54+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
55+
except ImportError:
56+
import gbulb
57+
gbulb.install()
5558

5659
import gettext
5760

qui/tools/qubes_device_agent.py

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

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

4146
# pylint: enable=wrong-import-position
4247

@@ -256,10 +261,10 @@ async def handle_request(self, params, service, source_domain):
256261
def main():
257262
args = parser.parse_args()
258263

259-
gbulb.install()
260264
agent = DeviceAgent(args.socket_path)
261265

262-
asyncio.run(agent.run())
266+
loop = asyncio.get_event_loop()
267+
loop.run_until_complete(agent.run())
263268

264269

265270
if __name__ == "__main__":

qui/tray/domains.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
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
30-
31-
gbulb.install()
29+
try:
30+
from gi.events import GLibEventLoopPolicy
31+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
32+
except ImportError:
33+
import gbulb
34+
gbulb.install()
3235

3336
import gettext
3437

qui/tray/updates.py

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

26-
import gbulb
27-
28-
gbulb.install()
26+
try:
27+
from gi.events import GLibEventLoopPolicy
28+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
29+
except ImportError:
30+
import gbulb
31+
gbulb.install()
2932

3033
import gettext
3134

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)