File: asyncio_deep.rst

package info (click to toggle)
python-sdbus 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 980 kB
  • sloc: python: 7,783; ansic: 2,524; makefile: 9; sh: 4
file content (42 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Asyncio advanced topics
+++++++++++++++++++++++++

.. py:currentmodule:: sdbus

Signals without data
^^^^^^^^^^^^^^^^^^^^

D-Bus allows signals to not carry any data. Such signals have the
type signature of ``""``. (empty string)

To emit such signals the :py:meth:`emit <DbusSignalAsync.emit>` must
be explicitly called with ``None``.

Example of an empty signal::

    from asyncio import new_event_loop
    from sdbus import DbusInterfaceCommonAsync, dbus_signal_async


    class ExampleInterface(
        DbusInterfaceCommonAsync,
        interface_name="org.example.signal"
    ):

        @dbus_signal_async("")
        def name_invalidated(self) -> None:
            raise NotImplementedError


    test_object = ExampleInterface()


    async def emit_empty_signal() -> None:
        test_object.export_to_dbus("/")

        test_object.name_invalidated.emit(None)


    loop = new_event_loop()
    loop.run_until_complete(emit_empty_signal())