-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/context manager #26 #45
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ on: | |
| permissions: | ||
| contents: write | ||
|
|
||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,35 +36,32 @@ from concurrent.futures import ThreadPoolExecutor | |||||
| from radical.asyncflow import WorkflowEngine | ||||||
|
|
||||||
| backend = await ConcurrentExecutionBackend(ThreadPoolExecutor()) | ||||||
| flow = await WorkflowEngine.create(backend=backend) | ||||||
|
|
||||||
| async def main(): | ||||||
| @flow.function_task | ||||||
| async def task1(*args): | ||||||
| return time.time() | ||||||
| async with WorkflowEngine(backend=backend) as flow: | ||||||
|
||||||
| async with WorkflowEngine(backend=backend) as flow: | |
| async with await WorkflowEngine.create(backend=backend) as flow: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ We initialize the workflow engine with a `ConcurrentExecutionBackend` using Pyth | |
|
|
||
| ```python | ||
| backend = await ConcurrentExecutionBackend(ThreadPoolExecutor()) | ||
| flow = await WorkflowEngine.create(backend=backend) | ||
| async with WorkflowEngine.create(backend=backend) as flow: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ``` | ||
|
|
||
| --- | ||
|
|
@@ -90,9 +90,6 @@ async def main(): | |
| end_time = time.time() | ||
| print(f"\nWorkflow completed in: {end_time - start_time:.2f} seconds") | ||
|
|
||
| # Shutdown the workflow engine | ||
| await flow.shutdown() | ||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ from radical.asyncflow import WorkflowEngine | |
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
||
| backend = await ConcurrentExecutionBackend(ThreadPoolExecutor()) | ||
| asyncflow = await WorkflowEngine.create(backend=backend) | ||
| async with WorkflowEngine.create(backend=backend) as flow: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ``` | ||
|
|
||
| ### Define Tasks | ||
|
|
@@ -116,7 +116,6 @@ await asyncio.gather( # (1)! | |
| end_time = time.time() | ||
| print(f"\nTotal time running asynchronously is: {end_time - start_time:.2f}s") | ||
|
|
||
| await asyncflow.shutdown() # (2)! | ||
| ``` | ||
|
|
||
| 1. Run all composite workflow blocks concurrently | ||
|
|
@@ -311,8 +310,5 @@ await block3 | |
| ``` | ||
|
|
||
|
|
||
| !!! warning | ||
| Do not forget to `await asyncflow.shutdown()` when you are done — otherwise, resources may remain allocated. | ||
|
|
||
| !!! tip | ||
| You can replace `ConcurrentExecutionBackend` with `RadicalExecutionBackend` if you want to run on an HPC cluster instead of local threads/processes. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -51,7 +51,7 @@ from radical.asyncflow import WorkflowEngine | |||||
|
|
||||||
| # HPC backend configuration | ||||||
| backend = RadicalExecutionBackend({'resource': 'local.localhost'}) # (1)! | ||||||
| flow = WorkflowEngine(backend=backend) | ||||||
| async with WorkflowEngine(backend=backend) as flow: | ||||||
|
||||||
| async with WorkflowEngine(backend=backend) as flow: | |
| async with await WorkflowEngine.create(backend=backend) as flow: |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,7 @@ from radical.asyncflow import ConcurrentExecutionBackend | |||||
| async def run(): | ||||||
| # Create backend and workflow | ||||||
| backend = await ConcurrentExecutionBackend(ThreadPoolExecutor(max_workers=3)) | ||||||
| flow = await WorkflowEngine.create(backend=backend) | ||||||
| async with WorkflowEngine(backend=backend) as flow: | ||||||
|
||||||
| async with WorkflowEngine(backend=backend) as flow: | |
| async with await WorkflowEngine.create(backend=backend) as flow: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
WorkflowEngineshould be instantiated using theawait WorkflowEngine.create(...)factory method to ensure all its async components are started correctly. UsingWorkflowEngine(...)directly will result in a non-functional engine because it bypasses necessary initialization steps.