diff --git a/colcon_parallel_executor/event/__init__.py b/colcon_parallel_executor/event/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/colcon_parallel_executor/event/executor.py b/colcon_parallel_executor/event/executor.py new file mode 100644 index 0000000..50b02dd --- /dev/null +++ b/colcon_parallel_executor/event/executor.py @@ -0,0 +1,16 @@ +# Copyright 2025 Open Source Robotics Foundation, Inc. +# Licensed under the Apache License, Version 2.0 + + +class ParallelStatus: + """An event containing the identifiers of in-progress jobs.""" + + __slots__ = ('processing', ) + + def __init__(self, processing): + """ + Construct a ParallelStatus. + + :param processing list: The in-progress job identifiers + """ + self.processing = tuple(processing) diff --git a/colcon_parallel_executor/event_handler/__init__.py b/colcon_parallel_executor/event_handler/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/colcon_parallel_executor/event_handler/parallel_status.py b/colcon_parallel_executor/event_handler/parallel_status.py new file mode 100644 index 0000000..56a7ec4 --- /dev/null +++ b/colcon_parallel_executor/event_handler/parallel_status.py @@ -0,0 +1,32 @@ +# Copyright 2025 Open Source Robotics Foundation, Inc. +# Licensed under the Apache License, Version 2.0 + +import sys + +from colcon_core.event_handler import EventHandlerExtensionPoint +from colcon_core.plugin_system import satisfies_version +from colcon_parallel_executor.event.executor import ParallelStatus + + +class ParallelStatusEventHandler(EventHandlerExtensionPoint): + """ + Periodically print a reminder of the currently executing jobs. + + This extension is only enabled by default if stdout is a tty-like device. + + This extension handles events of the following types: + - :py:class:`colcon_parallel_executor.event.executor.ParallelStatus` + """ + + def __init__(self): # noqa: D107 + super().__init__() + satisfies_version( + EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') + + self.enabled = sys.stdout.isatty() + + def __call__(self, event): # noqa: D102 + data = event[0] + + if isinstance(data, ParallelStatus): + print(f"[Processing: {', '.join(sorted(data.processing))}]") diff --git a/colcon_parallel_executor/executor/parallel.py b/colcon_parallel_executor/executor/parallel.py index da7c902..fee4357 100644 --- a/colcon_parallel_executor/executor/parallel.py +++ b/colcon_parallel_executor/executor/parallel.py @@ -17,6 +17,7 @@ from colcon_core.plugin_system import satisfies_version from colcon_core.subprocess import new_event_loop from colcon_core.subprocess import SIGINT_RESULT +from colcon_parallel_executor.event.executor import ParallelStatus logger = colcon_logger.getChild(__name__) @@ -43,7 +44,7 @@ class ParallelExecutorExtension(ExecutorExtensionPoint): def __init__(self): # noqa: D107 super().__init__() satisfies_version( - ExecutorExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') + ExecutorExtensionPoint.EXTENSION_POINT_VERSION, '^1.1') def add_arguments(self, *, parser): # noqa: D102 max_workers_default = os.cpu_count() or 4 @@ -162,9 +163,8 @@ async def _execute(self, args, jobs, *, on_error): futures.keys(), timeout=30, return_when=FIRST_COMPLETED) if not done_futures: # timeout - print( - '[Processing: %s]' % ', '.join(sorted( - f.identifier for f in futures.values()))) + self.put_event_into_queue(ParallelStatus(tuple( + f.identifier for f in futures.values()))) # check results of done futures for done_future in done_futures: diff --git a/setup.cfg b/setup.cfg index be64216..453ac29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ keywords = colcon [options] python_requires = >=3.6 install_requires = - colcon-core>=0.3.15 + colcon-core>=0.19.0 packages = find: zip_safe = true @@ -62,6 +62,8 @@ markers = linter [options.entry_points] +colcon_core.event_handler = + parallel_status = colcon_parallel_executor.event_handler.parallel_status:ParallelStatusEventHandler colcon_core.executor = parallel = colcon_parallel_executor.executor.parallel:ParallelExecutorExtension diff --git a/stdeb.cfg b/stdeb.cfg index f6996c6..4b52f22 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,6 +1,6 @@ [colcon-parallel-executor] No-Python2: -Depends3: python3-colcon-core (>= 0.3.15) +Depends3: python3-colcon-core (>= 0.19.0) Suite: focal jammy noble bookworm trixie X-Python3-Version: >= 3.6 Debian-Version: 100 diff --git a/test/spell_check.words b/test/spell_check.words index 4e8916d..dced634 100644 --- a/test/spell_check.words +++ b/test/spell_check.words @@ -6,6 +6,7 @@ coroutine getaffinity getpid getsignal +isatty iscoroutinefunction iterdir linter