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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def __init__(self, executor: Executor):
    if not isinstance(executor, Executor):
        err = "Executor must be ThreadPoolExecutor or ProcessPoolExecutor"
        raise TypeError(err)

    if isinstance(executor, ProcessPoolExecutor) and cloudpickle is None:
        raise ImportError(
            "ProcessPoolExecutor requires 'cloudpickle'. "
            "Install it with: pip install cloudpickle"
        )

    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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
39
40
41
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
157
158
159
160
161
162
163
164
165
166
167
168
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
188
189
190
191
192
193
194
195
196
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
198
199
200
201
202
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
221
222
223
224
225
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
227
228
229
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.14/site-packages/radical/asyncflow/backends/execution/concurrent.py
231
232
233
234
235
236
237
238
239
240
241
242
243
@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