aiocoap.util.cli module¶
Helpers for creating server-style applications in aiocoap
Note that these are not particular to aiocoap, but are used at different places in aiocoap and thus shared here.
-
class
aiocoap.util.cli.
ActionNoYes
(option_strings, dest, default=True, required=False, help=None)¶ Bases:
argparse.Action
Simple action that automatically manages –{,no-}something style options
-
class
aiocoap.util.cli.
AsyncCLIDaemon
(*args, **kwargs)¶ Bases:
object
Helper for creating daemon-style CLI prorgrams.
Note that this currently doesn’t create a Daemon in the sense of doing a daemon-fork; that could be added on demand, though.
Subclass this and implement the
start()
method as an async function; it will be passed all the constructor’s arguments.When all setup is complete and the program is operational, return from the start method.
Implement the
shutdown()
coroutine and to do cleanup; what actually runs your program will, if possible, call that and await its return.Two usage patterns for this are supported:
Outside of an async context, run run
MyClass.sync_main()
, typically in the program’sif __name__ == "__main__":
section.To run a subclass of this in an existing loop, start it with
MyClass(...)
(possibly passing in the loop to run it on if not already in an async context), and then awaiting its.initializing
future. To stop it, await its.shutdown()
method.This pattern is going to be deprecated or removed entirely when ported to async context managers.
-
stop
(exitcode)¶ Stop the operation (and exit sync_main) at the next convenience.
-
classmethod
sync_main
(*args, **kwargs)¶ Run the application in an AsyncIO main loop, shutting down cleanly on keyboard interrupt.