Lets "task create" nodes run in parallel.#8
Lets "task create" nodes run in parallel.#8nelsonjchen wants to merge 1 commit intoWaveSpeedAI:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR converts the WaveSpeed task submission and status checking nodes to use async/await patterns, enabling parallel execution of multiple task nodes similar to the approach described in the ComfyUI blog post about unlimited parallel API nodes.
Key Changes:
- Converted
submit_taskandcheck_statusmethods to async functions - Implemented
asyncio.run_in_executor()to run blocking API calls in thread pools without blocking the event loop
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| model_uuid = task_info.get("modelUUID") | ||
| if not model_uuid: | ||
| if not model_uuid: |
There was a problem hiding this comment.
Trailing whitespace at the end of the line. This should be removed to maintain code cleanliness and avoid unnecessary diff noise in version control.
| ) | ||
|
|
||
| if not response: | ||
| if not response: |
There was a problem hiding this comment.
Trailing whitespace at the end of the line. This should be removed to maintain code cleanliness and avoid unnecessary diff noise in version control.
| wait_for_completion: Whether to wait for completion | ||
|
|
||
| Returns: | ||
| Returns: |
There was a problem hiding this comment.
Trailing whitespace at the end of the line. This should be removed to maintain code cleanliness and avoid unnecessary diff noise in version control.
|
|
||
| # Use asyncio to run the blocking operation in a thread pool | ||
| loop = asyncio.get_event_loop() | ||
|
|
There was a problem hiding this comment.
Trailing whitespace at the end of the line. This should be removed to maintain code cleanliness and avoid unnecessary diff noise in version control.
| timeout=max_wait_time | ||
| # Use asyncio to run the blocking operation in a thread pool | ||
| # This allows multiple tasks to run concurrently | ||
| loop = asyncio.get_event_loop() |
There was a problem hiding this comment.
Using asyncio.get_event_loop() is deprecated in Python 3.10+ and can cause issues. In async functions, you should use asyncio.get_running_loop() instead, which returns the currently running event loop. The get_event_loop() method may return a different loop or fail if no loop is running.
| print(f"Checking status for task {task_id}") | ||
|
|
||
| # Use asyncio to run the blocking operation in a thread pool | ||
| loop = asyncio.get_event_loop() |
There was a problem hiding this comment.
Using asyncio.get_event_loop() is deprecated in Python 3.10+ and can cause issues. In async functions, you should use asyncio.get_running_loop() instead, which returns the currently running event loop. The get_event_loop() method may return a different loop or fail if no loop is running.
| error_message = str(e) | ||
| print(f"Error in WaveSpeedTaskSubmit: {error_message}") | ||
| raise Exception(f"WaveSpeedTaskSubmit failed: {error_message}") | ||
| raise Exception(f"WaveSpeedTaskSubmit failed: {error_message}") |
There was a problem hiding this comment.
Extra space after colon in the error message. The line has two spaces after "failed:" instead of one, making it inconsistent with standard error message formatting.
| client: WaveSpeed API client | ||
| task_info: Task information from WaveSpeedTaskCreateDynamic | ||
| wait_for_completion: Whether to wait for completion | ||
| wait_for_completion: Whether to wait for completion |
There was a problem hiding this comment.
Extra space after colon in the parameter description. The line has two spaces after "completion:" instead of one, making it inconsistent with other parameter descriptions.
| else: | ||
| # Unknown status, throw error | ||
| raise Exception(f"Unknown task status: {status}") | ||
| raise Exception(f"Unknown task status: {status}") |
There was a problem hiding this comment.
Extra space after colon in the error message. The line has two spaces after "status:" instead of one, making it inconsistent with standard error message formatting.
Like https://blog.comfy.org/p/unlimited-parallel-api-nodes-and