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
1diff --git a/softwareproperties/SoftwareProperties.py b/softwareproperties/SoftwareProperties.py
2index 835a1c6..9e94fa6 100644
3--- a/softwareproperties/SoftwareProperties.py
4+++ b/softwareproperties/SoftwareProperties.py
5@@ -128,7 +128,8 @@ class SoftwareProperties(object):
6 " wait for all running threads (PPA key fetchers) to exit "
7 for t in threading.enumerate():
8 if t.ident != threading.current_thread().ident:
9- t.join()
10+ if not t.daemon:
11+ t.join()
12
13 def backup_apt_conf(self):
14 """Backup all apt configuration options"""
15diff --git a/softwareproperties/gtk/DialogUaAttach.py b/softwareproperties/gtk/DialogUaAttach.py
16index 221def4..20bb543 100644
17--- a/softwareproperties/gtk/DialogUaAttach.py
18+++ b/softwareproperties/gtk/DialogUaAttach.py
19@@ -25,6 +25,7 @@ from softwareproperties.gtk.utils import setup_ui
20 from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate
21 from uaclient.api.u.pro.attach.magic.wait.v1 import MagicAttachWaitOptions, wait
22 from uaclient.exceptions import MagicAttachTokenError
23+import threading
24
25 class DialogUaAttach:
26 def __init__(self, parent, datadir, ua_object):
27@@ -135,8 +136,6 @@ class DialogUaAttach:
28 self.attach()
29
30 def on_cancel_clicked(self, button):
31- if self.poll:
32- GLib.Thread.unref(self.poll)
33 self.dialog.response(Gtk.ResponseType.CANCEL)
34
35 def poll_for_magic_token(self):
36@@ -168,7 +167,7 @@ class DialogUaAttach:
37 print(e)
38 return
39 self.update_state()
40- self.poll = GLib.Thread.new("poll", self.poll_for_magic_token)
41+ threading.Thread(target=self.poll_for_magic_token, daemon=True).start()
42
43 def on_radio_toggled(self, button):
44 self.update_state()

Subscribers

People subscribed via source and target branches