Skip to content

[th/nmclient-wait-shutdown] libnm: add nm_client_wait_shutdown() function for cleaning up NMClient

Thomas Haller requested to merge th/nmclient-wait-shutdown into main

It's not entirely trivial to let the user handle this. Also, because glib provides no convenient API to integrate a GMainContext in another GMainContext (like nm_utils_g_main_context_create_integrate_source()).

Add a fire-and-forget function to make that simpler.

The following test script will run out of file descriptors, when wait_shutdown() is not used:

#!/bin/python

import gi

gi.require_version("NM", "1.0")
from gi.repository import NM, GLib

for i in range(1200):
   print(f">>>{i}")

   ctx = GLib.MainContext()
   ctx.push_thread_default()
   nmc = NM.Client.new()
   ctx.pop_thread_default()

   def cb(unused, result, i):
       try:
           NM.Client.wait_shutdown_finish(result)
       except Exception:
           # cannot happen
           assert False
       else:
           print(f">>>>> {i} complete")

   nmc.wait_shutdown(True, None, cb, i)
   while GLib.MainContext.default().iteration(False):
       pass

Merge request reports