Skip to content
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

WIP: Add support for running in environments that have a running asyncio loop #388

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

treo
Copy link
Contributor

@treo treo commented Mar 12, 2025

Description

Jupyter's ipykernel starts an asyncio loop in the same thread as it is executing the xircuits workflow. When using AsyncComponent (see #351) in that environment directly, we would encounter an exception thrown by AsyncToSync telling us to just await the thing.

You cannot use AsyncToSync in the same thread as an async event loop - just await the async function directly.

A simple workaround to this is to not use ipykernel based execution by selecting the "Terminal Run" option. However, that requires the user to know about the issue and understand the workaround.

This change instead allows the workflow to adapt to its environment.

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Jupyter's ipykernel starts an asyncio loop in the same thread as it is executing the
xircuits workflow. When using AsyncComponent in that environment directly, we would
encounter an exception thrown by AsyncToSync telling us to just await the thing.

A simple workaround to this is to not use ipykernel based execution by selecting the
"Terminal Run" option. However, that requires the user to know about the issue and
understand the workaround.

This change instead allows the workflow to adapt to its environment.
Copy link

Binder 👈 Launch a binder notebook on branch XpressAI/xircuits/paul/async_runner_support

@treo treo requested a review from MFA-X-AI March 12, 2025 10:57
@treo treo changed the title Add support for running in environments that have a running asyncio loop WIP: Add support for running in environments that have a running asyncio loop Mar 12, 2025
@treo
Copy link
Contributor Author

treo commented Mar 12, 2025

It seems that there may be additional constraints that need to be kept in mind when using this approach.

In particular, it looks like the converse component library doesn't like it.

@treo
Copy link
Contributor Author

treo commented Mar 12, 2025

I've found a way that seems to work, but it will require a patch to converse as well. The good news is that it should simplify the ConverseRun component so it can simply await the server task, but maybe there are issues with not natively async component libraries that start servers? I haven't tested that yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant