Skip to content

radical.asyncflow.backends.execution.concurrent

ConcurrentExecutionBackend

ConcurrentExecutionBackend(executor: Executor)

Bases: BaseExecutionBackend

Simple async-only concurrent execution backend.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
16
17
18
19
20
21
22
23
24
25
def __init__(self, executor: Executor):
    if not isinstance(executor, Executor):
        err = "Executor must be ThreadPoolExecutor or ProcessPoolExecutor"
        raise TypeError(err)

    self.executor = executor
    self.tasks: dict[str, asyncio.Task] = {}
    self.session = Session()
    self._callback_func: Optional[Callable] = None
    self._initialized = False

__await__

__await__()

Make backend awaitable.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
27
28
29
def __await__(self):
    """Make backend awaitable."""
    return self._async_init().__await__()

submit_tasks async

submit_tasks(tasks: list[dict[str, Any]]) -> list[Task]

Submit tasks for execution.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
122
123
124
125
126
127
128
129
130
131
132
133
async def submit_tasks(self, tasks: list[dict[str, Any]]) -> list[asyncio.Task]:
    """Submit tasks for execution."""
    submitted_tasks = []

    for task in tasks:
        future = asyncio.create_task(self._handle_task(task))
        submitted_tasks.append(future)

        self.tasks[task["uid"]] = task
        self.tasks[task["uid"]]["future"] = future

    return submitted_tasks

cancel_task async

cancel_task(uid: str) -> bool

Cancel a task by its UID.

Parameters:

Name Type Description Default
uid str

The UID of the task to cancel.

required

Returns:

Name Type Description
bool bool

True if the task was found and cancellation was attempted, False otherwise.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
async def cancel_task(self, uid: str) -> bool:
    """Cancel a task by its UID.

    Args:
        uid (str): The UID of the task to cancel.

    Returns:
        bool: True if the task was found and cancellation was attempted,
              False otherwise.
    """
    if uid in self.tasks:
        task = self.tasks[uid]
        future = task["future"]
        if future and future.cancel():
            self._callback_func(task, "CANCELED")
            return True
    return False

cancel_all_tasks async

cancel_all_tasks() -> int

Cancel all running tasks.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
153
154
155
156
157
158
159
160
161
async def cancel_all_tasks(self) -> int:
    """Cancel all running tasks."""
    cancelled_count = 0
    for task in self.tasks.values():
        future = task["future"]
        future.cancel()
        cancelled_count += 1
    self.tasks.clear()
    return cancelled_count

shutdown async

shutdown() -> None

Shutdown the executor.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
163
164
165
166
167
async def shutdown(self) -> None:
    """Shutdown the executor."""
    await self.cancel_all_tasks()
    self.executor.shutdown(wait=True)
    logger.info("Concurrent execution backend shutdown complete")

__aenter__ async

__aenter__()

Async context manager entry.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
186
187
188
189
190
async def __aenter__(self):
    """Async context manager entry."""
    if not self._initialized:
        await self._async_init()
    return self

__aexit__ async

__aexit__(exc_type, exc_val, exc_tb)

Async context manager exit.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
192
193
194
async def __aexit__(self, exc_type, exc_val, exc_tb):
    """Async context manager exit."""
    await self.shutdown()

create async classmethod

create(executor: Executor)

Alternative factory method for creating initialized backend.

Parameters:

Name Type Description Default
executor Executor

A concurrent.Executor instance (ThreadPoolExecutor or ProcessPoolExecutor).

required

Returns:

Type Description

Fully initialized ConcurrentExecutionBackend instance.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
196
197
198
199
200
201
202
203
204
205
206
207
208
@classmethod
async def create(cls, executor: Executor):
    """Alternative factory method for creating initialized backend.

    Args:
        executor: A concurrent.Executor instance (ThreadPoolExecutor
                  or ProcessPoolExecutor).

    Returns:
        Fully initialized ConcurrentExecutionBackend instance.
    """
    backend = cls(executor)
    return await backend