launch.launch_service module

Module for the LaunchService class.

class launch.launch_service.LaunchService[source]

Bases: object

Service that manages the event loop and runtime for launched system.

__init__(*, argv: Iterable[str] | None = None, noninteractive: bool = False, debug: bool = False) None[source]

Create a LaunchService.

Param:

argv stored in the context for access by the entities, None results in []

Param:

noninteractive if True (not default), this service will assume it has no terminal associated e.g. it is being executed from a non interactive script

Param:

debug if True (not default), asyncio the logger are seutp for debug

property context

Getter for context.

emit_event(event: Event) None[source]

Emit an event synchronously and thread-safely.

If the LaunchService is not running, the event is queued until it is.

property event_loop

Getter for the event loop being used in the thread running the launch service.

include_launch_description(launch_description: LaunchDescription) None[source]

Evaluate a given LaunchDescription and visits all of its entities.

This method is thread-safe.

run(*, shutdown_when_idle=True) int[source]

Run an event loop and visit all entities of all included LaunchDescription instances.

This should only ever be run from the main thread and not concurrently with asynchronous runs (see run_async() documentation).

Note that KeyboardInterrupt is caught and ignored, as signals are handled separately. After the run ends, this behavior is undone.

Param:

shutdown_when_idle if True (default), the service will shutdown when idle

Returns:

the return code (non-zero if there are any errors)

async run_async(*, shutdown_when_idle=True) int[source]

Visit all entities of all included LaunchDescription instances asynchronously.

This should only ever be run from the main thread and not concurrently with other asynchronous runs.

Param:

shutdown_when_idle if True (default), the service will shutdown when idle.

Returns:

the return code (non-zero if there are any errors)

shutdown(force_sync=False) Coroutine | None[source]

Shutdown all on-going activities and then stop the asyncio run loop.

This will cause the running LaunchService to eventually exit.

Does nothing if the LaunchService is not running.

This will return an awaitable coroutine if called from within the loop.

This method is thread-safe.

property task

Return asyncio task associated with this launch service.