Skip to content

Commit 1efb41b

Browse files
committed
Plumb status updates through event handler
This will allow users to disable the event handler and silence the currently unconditional console output.
1 parent f52f1b4 commit 1efb41b

File tree

8 files changed

+57
-6
lines changed

8 files changed

+57
-6
lines changed

colcon_parallel_executor/event/__init__.py

Whitespace-only changes.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 Open Source Robotics Foundation, Inc.
2+
# Licensed under the Apache License, Version 2.0
3+
4+
5+
class ParallelStatus:
6+
"""An event containing the identifiers of in-progress jobs."""
7+
8+
__slots__ = ('processing', )
9+
10+
def __init__(self, processing):
11+
"""
12+
Construct a ParallelStatus.
13+
14+
:param processing list: The in-progress job identifiers
15+
"""
16+
self.processing = tuple(processing)

colcon_parallel_executor/event_handler/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 Open Source Robotics Foundation, Inc.
2+
# Licensed under the Apache License, Version 2.0
3+
4+
import sys
5+
6+
from colcon_core.event_handler import EventHandlerExtensionPoint
7+
from colcon_core.plugin_system import satisfies_version
8+
from colcon_parallel_executor.event.executor import ParallelStatus
9+
10+
11+
class ParallelStatusEventHandler(EventHandlerExtensionPoint):
12+
"""
13+
Periodically print a reminder of the currently executing jobs.
14+
15+
This extension is only enabled by default if stdout is a tty-like device.
16+
17+
This extension handles events of the following types:
18+
- :py:class:`colcon_parallel_executor.event.executor.ParallelStatus`
19+
"""
20+
21+
def __init__(self): # noqa: D107
22+
super().__init__()
23+
satisfies_version(
24+
EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
25+
26+
self.enabled = sys.stdout.isatty()
27+
28+
def __call__(self, event): # noqa: D102
29+
data = event[0]
30+
31+
if isinstance(data, ParallelStatus):
32+
print(f"[Processing: {', '.join(sorted(data.processing))}]")

colcon_parallel_executor/executor/parallel.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from colcon_core.plugin_system import satisfies_version
1818
from colcon_core.subprocess import new_event_loop
1919
from colcon_core.subprocess import SIGINT_RESULT
20+
from colcon_parallel_executor.event.executor import ParallelStatus
2021

2122
logger = colcon_logger.getChild(__name__)
2223

@@ -43,7 +44,7 @@ class ParallelExecutorExtension(ExecutorExtensionPoint):
4344
def __init__(self): # noqa: D107
4445
super().__init__()
4546
satisfies_version(
46-
ExecutorExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
47+
ExecutorExtensionPoint.EXTENSION_POINT_VERSION, '^1.1')
4748

4849
def add_arguments(self, *, parser): # noqa: D102
4950
max_workers_default = os.cpu_count() or 4
@@ -162,9 +163,8 @@ async def _execute(self, args, jobs, *, on_error):
162163
futures.keys(), timeout=30, return_when=FIRST_COMPLETED)
163164

164165
if not done_futures: # timeout
165-
print(
166-
'[Processing: %s]' % ', '.join(sorted(
167-
f.identifier for f in futures.values())))
166+
self.put_event_into_queue(ParallelStatus(tuple(
167+
f.identifier for f in futures.values())))
168168

169169
# check results of done futures
170170
for done_future in done_futures:

setup.cfg

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ keywords = colcon
2727
[options]
2828
python_requires = >=3.6
2929
install_requires =
30-
colcon-core>=0.3.15
30+
colcon-core>=0.19.0
3131
packages = find:
3232
zip_safe = true
3333

@@ -62,6 +62,8 @@ markers =
6262
linter
6363

6464
[options.entry_points]
65+
colcon_core.event_handler =
66+
parallel_status = colcon_parallel_executor.event_handler.parallel_status:ParallelStatusEventHandler
6567
colcon_core.executor =
6668
parallel = colcon_parallel_executor.executor.parallel:ParallelExecutorExtension
6769

stdeb.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[colcon-parallel-executor]
22
No-Python2:
3-
Depends3: python3-colcon-core (>= 0.3.15)
3+
Depends3: python3-colcon-core (>= 0.19.0)
44
Suite: focal jammy noble bookworm trixie
55
X-Python3-Version: >= 3.6
66
Debian-Version: 100

test/spell_check.words

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ coroutine
66
getaffinity
77
getpid
88
getsignal
9+
isatty
910
iscoroutinefunction
1011
iterdir
1112
linter

0 commit comments

Comments
 (0)