Skip to content

radical.asyncflow.backends.execution.concurrent

ConcurrentExecutionBackend

ConcurrentExecutionBackend(executor: Union[ThreadPoolExecutor, ProcessPoolExecutor])

Bases: BaseExecutionBackend

Simple async-only concurrent execution backend.

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

    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
23
24
25
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
118
119
120
121
122
123
124
125
126
127
128
129
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
148
149
150
151
152
153
154
155
156
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
158
159
160
161
162
async def shutdown(self) -> None:
    """Shutdown the executor."""
    await self.cancel_all_tasks()
    self.executor.shutdown(wait=True)
    print('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
179
180
181
182
183
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
185
186
187
async def __aexit__(self, exc_type, exc_val, exc_tb):
    """Async context manager exit."""
    await self.shutdown()

create async classmethod

create(executor: Union[ThreadPoolExecutor, ProcessPoolExecutor])

Factory method for creating initialized backend.

Source code in doc_env/lib/python3.13/site-packages/radical/asyncflow/backends/execution/concurrent.py
189
190
191
192
193
@classmethod
async def create(cls, executor: Union[ThreadPoolExecutor, ProcessPoolExecutor]):
    """Factory method for creating initialized backend."""
    backend = cls(executor)
    return await backend