Merge pull request #1509 from dbungert/journald-no-loop-pass

journald: stop passing a loop
This commit is contained in:
Dan Bungert 2022-12-06 18:02:11 -07:00 committed by GitHub
commit 0e846cd88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 14 deletions

View File

@ -297,10 +297,7 @@ class SubiquityClient(TuiApplication):
p('\x08 \n')
status = await spinning_wait("connecting", self._status_get())
journald_listen(
self.aio_loop,
[status.echo_syslog_id],
lambda e: print(e['MESSAGE']))
journald_listen([status.echo_syslog_id], lambda e: print(e['MESSAGE']))
if status.state == ApplicationState.STARTING_UP:
status = await spinning_wait(
"starting up", self._status_get(cur=status.state))
@ -357,11 +354,9 @@ class SubiquityClient(TuiApplication):
# the progress page
if hasattr(self.controllers, "Progress"):
journald_listen(
self.aio_loop,
[status.event_syslog_id],
self.controllers.Progress.event)
journald_listen(
self.aio_loop,
[status.log_syslog_id],
self.controllers.Progress.log_line)
if not status.cloud_init_ok:
@ -382,7 +377,6 @@ class SubiquityClient(TuiApplication):
# prompting for confirmation will be confusing.
os.system('stty sane')
journald_listen(
self.aio_loop,
[status.event_syslog_id],
self.subiquity_event_noninteractive,
seek=True)

View File

@ -19,7 +19,7 @@ import contextlib
from systemd import journal
def journald_listen(loop, identifiers, callback, seek=False):
def journald_listen(identifiers, callback, seek=False):
reader = journal.Reader()
args = []
for identifier in identifiers:
@ -37,6 +37,7 @@ def journald_listen(loop, identifiers, callback, seek=False):
return
for event in reader:
callback(event)
loop = asyncio.get_running_loop()
loop.add_reader(reader.fileno(), watch)
return reader.fileno()
@ -44,12 +45,12 @@ def journald_listen(loop, identifiers, callback, seek=False):
@contextlib.contextmanager
def journald_subscriptions(ids_callbacks, seek=False):
fds = set()
loop = asyncio.get_running_loop()
for ids, callback in ids_callbacks:
fds.add(journald_listen(loop, ids, callback, seek=seek))
fds.add(journald_listen(ids, callback, seek=seek))
try:
yield
finally:
loop = asyncio.get_running_loop()
for fd in fds:
loop.remove_reader(fd)

View File

@ -145,8 +145,7 @@ class InstallController(SubiquityController):
asyncio.create_task(self.stop_unattended_upgrades())
def start(self):
journald_listen(
self.app.aio_loop, [self.app.log_syslog_id], self.log_event)
journald_listen([self.app.log_syslog_id], self.log_event)
self.install_task = asyncio.create_task(self.install())
def tpath(self, *path):

View File

@ -103,8 +103,7 @@ class _CurtinCommand:
return cmd
async def start(self, context, **opts):
self._fd = journald_listen(
asyncio.get_running_loop(), [self._event_syslog_id], self._event)
self._fd = journald_listen([self._event_syslog_id], self._event)
# Yield to the event loop before starting curtin to avoid missing the
# first couple of events.
await asyncio.sleep(0)