Skip to content

Conversation

@samojavo
Copy link
Contributor

@samojavo samojavo commented Oct 25, 2025

Guard sync API when called from async contexts.

  • If called on the CocoIndex-managed loop: raise RuntimeError (prevents deadlock).
  • If called on a different running loop: emit a warning and run safely.
  • If no loop is running: run as usual.

Closes #1085.

Copy link
Member

@georgeh0 georgeh0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Code change looks pretty good! Please fix the CI check failure.

return self._event_loop

def run(self, coro: Coroutine[Any, Any, T]) -> T:
def run(self, coro):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A check failed. Looks like it's because this type annotation is removed. You may try to bring it back and locally run dmypy run python to see if the type checking passes.

@georgeh0
Copy link
Member

Format check failed. You may follow the guide here to do pre-commit install and run it locally. Thanks!

@samojavo
Copy link
Contributor Author

i did run ruff format so it should be fine now

Copy link
Member

@georgeh0 georgeh0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this!

@georgeh0 georgeh0 merged commit 6674dda into cocoindex-io:main Oct 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Raise an error if the sync version of our Python SDK method is called within an async context

2 participants