Skip to content

Commit 799e204

Browse files
authored
fix/Move the nest-asyncio apply into an init hook (#107)
We're seeing an issue where the nest_asyncio.apply() workaround for nested loops is breaking when we're dealing with a `uvloop`. We need to investigate further, or remove the bandaid solution. In the meantime, we can unblock a simple import of the client in these environments by doing the apply only when the hook is run.
1 parent 421efb1 commit 799e204

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: src/unstructured_client/_hooks/custom/split_pdf_hook.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
MIN_PAGES_PER_SPLIT = 2
4242
MAX_PAGES_PER_SPLIT = 20
4343

44-
nest_asyncio.apply()
4544

4645

4746
async def run_tasks(tasks):
@@ -69,6 +68,10 @@ class SplitPdfHook(SDKInitHook, BeforeRequestHook, AfterSuccessHook, AfterErrorH
6968
"""
7069

7170
def __init__(self) -> None:
71+
# This allows us to use an event loop in an env with an existing loop
72+
# Temporary fix until we can improve the async splitting behavior
73+
nest_asyncio.apply()
74+
7275
self.client: Optional[requests.Session] = None
7376
self.coroutines_to_execute: dict[
7477
str, list[Coroutine[Any, Any, requests.Response]]

0 commit comments

Comments
 (0)