fix/allow asyncio page splitting in nested event loops#104
Merged
Conversation
We're now using asyncio for page split concurrency, but because the client itself is not async, we need to manage our own event loop. This complains if your environment already has a running event loop. For instance, setting `split_pdf_page=True` in a jupyter cell will give you `RuntimeError: This event loop is already running`. Turns out there's a simple library to allow for nested event loops. We just apply the monkeypatch in split_pdf_hook.py and the error goes away. To verify, you'll need to run `pip install -e .` to install the local version of the client. Run `make run-jupyter` and open up the sample notebook in `_jupyter/`. Try making a request with page splitting enabled and you'll see the above error. Then, check out this branch, install locally again, restart your jupyter kernel, and the error is fixed.
badGarnet
approved these changes
Jun 4, 2024
Collaborator
badGarnet
left a comment
There was a problem hiding this comment.
with a pin that this is only a temporary solution since this dep is an archived repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We're now using asyncio for page split concurrency, but because the client itself is not async, we need to manage our own event loop. This complains if your environment already has a running event loop. For instance, setting
split_pdf_page=Truein a jupyter cell will give youRuntimeError: This event loop is already running.Turns out there's a simple library to allow for nested event loops. We just apply the monkeypatch in split_pdf_hook.py and the error goes away.
To verify, you'll need to install the current client on main, test in jupyter, then install on this branch and verify the error is gone.
pip install -e .in your pyenv to install the local version of the clientmake run-jupyterand open up the sample notebook in_jupyter/.split_pdf_page=True. Change theserver_urlto hit your local server, or add your freemium api key to the snippet. Once the result starts coming back, you should get the above error.