Esempio n. 1
0
def test_on_shutdown_function():
    context = Context()
    context.init()

    callback_called = False

    def on_shutdown():
        nonlocal callback_called
        callback_called = True

    context.on_shutdown(on_shutdown)

    context.shutdown()

    assert callback_called
Esempio n. 2
0
def init(
    *,
    args: Optional[List[str]] = None,
    context: Context = None,
    domain_id: Optional[int] = None,
    signal_handler_options: Optional[SignalHandlerOptions] = None,
) -> None:
    """
    Initialize ROS communications for a given context.

    :param args: List of command line arguments.
    :param context: The context to initialize. If ``None``, then the default context is used
        (see :func:`.get_default_context`).
    :param domain_id: ROS domain id.
    :param signal_handler_options: Indicate which signal handlers to install.
        If `None`, SIGINT and SIGTERM will be installed when initializing the default context.
    """
    context = get_default_context() if context is None else context
    if signal_handler_options is None:
        if context is None or context is get_default_context():
            signal_handler_options = SignalHandlerOptions.ALL
        else:
            signal_handler_options = SignalHandlerOptions.NO
    install_signal_handlers(signal_handler_options)
    return context.init(args, domain_id=domain_id)
Esempio n. 3
0
def test_on_shutdown_method():
    context = Context()
    context.init()

    callback_called = False

    class SomeClass:

        def on_shutdown(self):
            nonlocal callback_called
            callback_called = True

    instance = SomeClass()
    context.on_shutdown(instance.on_shutdown)

    context.shutdown()

    assert callback_called
Esempio n. 4
0
def init(*, args: Optional[List[str]] = None, context: Context = None) -> None:
    """
    Initialize ROS communications for a given context.

    :param args: List of command line arguments.
    :param context: The context to initialize. If ``None``, then the default context is used
        (see :func:`.get_default_context`).
    """
    context = get_default_context() if context is None else context
    return context.init(args)
Esempio n. 5
0
def non_default_context():
    context = Context()
    context.init()
    yield context
    context.try_shutdown()