NetworkManager/examples/python/gi
Thomas Haller 88724ff169
libnm: add nm_client_wait_shutdown() function for cleaning up NMClient
Add a fire-and-forget function to wait for shutdown to be complete.

It's not entirely trivial to ensure all resources of NMClient are
cleaned up. That matters only if NMClient uses a temporary GMainContext
that the user wants to release while the application continues. For
example, to do some short-lived operations an a worker thread. It's
not trivial also because glib provides no convenient API to integrate
a GMainContext in another GMainContext. We have that code as
nm_utils_g_main_context_create_integrate_source(), so add a helper
function to allow the user to do this.

The function allows to omit the callback, in which case the caller
wouldn't know when shutdown is complete. That would still be useful
however, when integrating the client's context into the caller's
context, so that the client's context gets automatically iterated
until completion.

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
2022-10-14 17:48:24 +02:00
..
add_connection.py docs: update URL for latest online documentation 2021-09-24 14:41:35 +02:00
checkpoint.py examples: improve finding last checkpoint in "checkpoint.py" 2022-05-02 18:04:37 +02:00
deactivate-all.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
device-state-ip4config.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
dns.py examples/python: avoid Python2 "print" statement 2022-02-14 17:02:34 +01:00
firewall-zone.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
get-active-connections.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
get-devices.py examples/python: avoid Python2 "print" statement 2022-02-14 17:02:34 +01:00
get-interface-flags.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
get-lldp-neighbors.py examples/python: avoid Python2 "print" statement 2022-02-14 17:02:34 +01:00
get_ips.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
gmaincontext.py libnm: add nm_client_wait_shutdown() function for cleaning up NMClient 2022-10-14 17:48:24 +02:00
list-connections.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-add-connection2.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-connection-update-stable-id.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-keyfile.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-up-many.py examples: rework nm-up-many.py for ratelimiting parallel activations 2021-06-22 09:47:44 +02:00
nm-update2.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-wg-set all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
ovs-external-ids.py examples/trivial: fix black formatting of python code 2021-05-27 14:08:47 +02:00
README examples: add README for examples/python/gi 2015-12-07 15:59:20 +01:00
setting-user-data.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
show-wifi-networks.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
update-ip4-method.py docs: update URL for latest online documentation 2021-09-24 14:41:35 +02:00
vpn-import.py examples: use python3 compatible exception syntax 2021-03-16 07:55:12 +01:00
wifi-p2p.py all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00

These examples show how to call libnm from Python using
GObject introspection.