Skip to content

fix/allow asyncio page splitting in nested event loops#104

Merged
awalker4 merged 1 commit intomainfrom
fix/nested-event-loops
Jun 4, 2024
Merged

fix/allow asyncio page splitting in nested event loops#104
awalker4 merged 1 commit intomainfrom
fix/nested-event-loops

Conversation

@awalker4
Copy link
Copy Markdown
Collaborator

@awalker4 awalker4 commented Jun 4, 2024

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 install the current client on main, test in jupyter, then install on this branch and verify the error is gone.

  • Checkout the main branch and run pip install -e . in your pyenv to install the local version of the client
  • Run make run-jupyter and open up the sample notebook in _jupyter/.
  • Update the sample code to use split_pdf_page=True. Change the server_url to 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.
  • Checkout this branch and install locally again
  • Restart your kernel and try your snippet again. The error should be gone.

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.
@awalker4 awalker4 enabled auto-merge (squash) June 4, 2024 21:18
Copy link
Copy Markdown
Collaborator

@badGarnet badGarnet left a comment

Choose a reason for hiding this comment

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

with a pin that this is only a temporary solution since this dep is an archived repo

@awalker4 awalker4 merged commit 224f9ad into main Jun 4, 2024
@awalker4 awalker4 deleted the fix/nested-event-loops branch June 4, 2024 22:27
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.

2 participants