Easy GDBus service creation with exit-on-idle functionality
Project description
GDBus Util
This is a collection of utilities to create GDBus services in Python.
DBusObject
This is a class that can be used to define a D-Bus object and register it on a D-Bus service.
Take a look at examples/simple/hello-service.py
for a simple example
of how to use it.
ExitOnIdleService
This class implements race-free exit-on-idle for a D-Bus service. It is useful for services that are meant to be started on demand and exit automatically when they are no longer needed.
It takes a timeout in seconds as a parameter and will exit the service
if it is idle at the end of the timeout. A check_idle
method can be
overridden or passed as a parameter to __init__
. The DBusObject
has
a check_idle
method which checks if there are any ongoing method calls.
If the ExitOnIdleService
instance is also a DBusObject
, it will
use that method as the idle check by default.
The timer can be reset by calling the reset_idle_timer
method. If the
ExitOnIdleService
instance is also a DBusObject
, it will
automatically reset the idle timeout whenever a method call is received
(or a property is read or written).
To avoid that requests are lost when the service is exiting, it unregisters the bus name first and then handles any pending requests before exiting.
If the service is run as a systemd service, systemd will be notified that the service is stopping, so that it will queue any start requests instead of assuming that the service is still running.
Take a look at examples/exit-on-idle/hello-service.py
for a simple
example or examples/more-complex/accounts-service.py
for a more
complex example of how to implement an exit-on-idle service.
Credits
The race-free exit-on-idle implementation was inspired by
https://github.com/cgwalters/test-exit-on-idle and systemd's
bus_event_loop_with_idle
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gdbus_util-0.0.1.tar.gz
.
File metadata
- Download URL: gdbus_util-0.0.1.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc2597ff783d596f6283320697990a1dd5f8a484f77970511097bfc729efb3ab |
|
MD5 | b03516b8dadf2f677ec994bb2ea985a8 |
|
BLAKE2b-256 | c834cc54ab12dc001e9c6c6b280ea09f10a21cf98969ab2eead3ce9d966d34e9 |
File details
Details for the file gdbus_util-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: gdbus_util-0.0.1-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd899f809834f816419f4f27173111a9685b4f0ed7a5975cd7beb1d45ea1e54d |
|
MD5 | d0eb42f37c77f76825bdc9403ef2af69 |
|
BLAKE2b-256 | 03c71f95dea2760d56c04648d889ef9e0204109ced485c69069f56620e984884 |