Merge ~nteodosio/software-properties:threading into software-properties:ubuntu/master

Proposed by Nathan Teodosio
Status: Merged
Merge reported by: Nathan Teodosio
Merged at revision: 4657ca5da215eb24805ac5b71c7962365a0757ce
Proposed branch: ~nteodosio/software-properties:threading
Merge into: software-properties:ubuntu/master
Diff against target: 44 lines (+4/-4)
2 files modified
softwareproperties/SoftwareProperties.py (+2/-1)
softwareproperties/gtk/DialogUaAttach.py (+2/-3)
Reviewer Review Type Date Requested Status
Sebastien Bacher Pending
Review via email: mp+434815@code.launchpad.net

Description of the change

GLib.Thread is not available in Bionic and Focal: https://gitlab.gnome.org/GNOME/glib/-/issues/602.

Use Python threading module.

Also need to let daemonic threads go lest software-properties becomes uncloseable after invoking the UA attach dialog without subsequent verification of the PIN in the magic attach flow.

That, in my reading, is backed up by the definition of daemonic thread[1]:

> A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left.

[1]: https://docs.python.org/3/library/threading.html

To post a comment you must log in.
Revision history for this message
Nathan Teodosio (nteodosio) wrote (last edit ):

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/softwareproperties/SoftwareProperties.py b/softwareproperties/SoftwareProperties.py
index 835a1c6..9e94fa6 100644
--- a/softwareproperties/SoftwareProperties.py
+++ b/softwareproperties/SoftwareProperties.py
@@ -128,7 +128,8 @@ class SoftwareProperties(object):
128 " wait for all running threads (PPA key fetchers) to exit "128 " wait for all running threads (PPA key fetchers) to exit "
129 for t in threading.enumerate():129 for t in threading.enumerate():
130 if t.ident != threading.current_thread().ident:130 if t.ident != threading.current_thread().ident:
131 t.join()131 if not t.daemon:
132 t.join()
132133
133 def backup_apt_conf(self):134 def backup_apt_conf(self):
134 """Backup all apt configuration options"""135 """Backup all apt configuration options"""
diff --git a/softwareproperties/gtk/DialogUaAttach.py b/softwareproperties/gtk/DialogUaAttach.py
index 221def4..20bb543 100644
--- a/softwareproperties/gtk/DialogUaAttach.py
+++ b/softwareproperties/gtk/DialogUaAttach.py
@@ -25,6 +25,7 @@ from softwareproperties.gtk.utils import setup_ui
25from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate25from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate
26from uaclient.api.u.pro.attach.magic.wait.v1 import MagicAttachWaitOptions, wait26from uaclient.api.u.pro.attach.magic.wait.v1 import MagicAttachWaitOptions, wait
27from uaclient.exceptions import MagicAttachTokenError27from uaclient.exceptions import MagicAttachTokenError
28import threading
2829
29class DialogUaAttach:30class DialogUaAttach:
30 def __init__(self, parent, datadir, ua_object):31 def __init__(self, parent, datadir, ua_object):
@@ -135,8 +136,6 @@ class DialogUaAttach:
135 self.attach()136 self.attach()
136137
137 def on_cancel_clicked(self, button):138 def on_cancel_clicked(self, button):
138 if self.poll:
139 GLib.Thread.unref(self.poll)
140 self.dialog.response(Gtk.ResponseType.CANCEL)139 self.dialog.response(Gtk.ResponseType.CANCEL)
141140
142 def poll_for_magic_token(self):141 def poll_for_magic_token(self):
@@ -168,7 +167,7 @@ class DialogUaAttach:
168 print(e)167 print(e)
169 return168 return
170 self.update_state()169 self.update_state()
171 self.poll = GLib.Thread.new("poll", self.poll_for_magic_token)170 threading.Thread(target=self.poll_for_magic_token, daemon=True).start()
172171
173 def on_radio_toggled(self, button):172 def on_radio_toggled(self, button):
174 self.update_state()173 self.update_state()

Subscribers

People subscribed via source and target branches