summaryrefslogtreecommitdiff
path: root/examples/python/gi/gmaincontext.py
Commit message (Collapse)AuthorAgeFilesLines
* examples: fix code formatting in "gmaincontext.py"Thomas Haller2022-10-251-1/+1
|
* examples: avoid unreachable code in "gmaincontext.py"Thomas Haller2022-10-251-7/+5
| | | | lgtm.com warns about this. Avoid it.
* examples: drop unused import from "gmaincontext.py" exampleThomas Haller2022-10-251-1/+0
| | | | Complained by lgtm.com.
* examples: avoid lgtm warning about calling traceback.format_exception()Thomas Haller2022-10-251-1/+1
| | | | | | | lgtm.com says: Call to function format_exception with too few arguments; should be no fewer than 3.
* libnm: add nm_client_wait_shutdown() function for cleaning up NMClientThomas Haller2022-10-141-42/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* examples: fix tracking destruction in destroy_nmc()Thomas Haller2022-07-131-3/+3
| | | | | | | | | | While iterating the context (once), multiple sources can be dispatched. So if we get a timeout and shortly after the weak-ref callback, then we still need to honor the weak-ref. In particular, because weak_ref.unref() is not safe to do after the object was already destroyed. So we need to be correct about tracking destruction.
* example: add python example for libnm, NMClient, GMainContext and asyncThomas Haller2022-07-051-0/+448
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1290