Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plumb status updates through event handler #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
16 changes: 16 additions & 0 deletions colcon_parallel_executor/event/executor.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
32 changes: 32 additions & 0 deletions colcon_parallel_executor/event_handler/parallel_status.py
Original file line number Diff line number Diff line change
@@ -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))}]")
8 changes: 4 additions & 4 deletions colcon_parallel_executor/executor/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coroutine
getaffinity
getpid
getsignal
isatty
iscoroutinefunction
iterdir
linter
Expand Down
Loading