File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import asyncio
12import shutil
23import tempfile
34from collections .abc import AsyncGenerator , Iterable , Iterator
@@ -55,7 +56,13 @@ async def extract_content(
5556 ) -> AsyncGenerator [Result , None ]:
5657 docs , path_or_streams = map_and_preserve (_to_docling , docs )
5758 outputs = self ._converter .convert_all (path_or_streams , raises_on_error = False )
58- for doc , res in zip (docs , outputs , strict = True ):
59+
60+ sentinel = object ()
61+ while True :
62+ res = await asyncio .to_thread (next , outputs , sentinel )
63+ if res is sentinel :
64+ return
65+ doc = next (docs )
5966 yield _to_result (res , doc , output_format , output_path = output_path )
6067
6168 @classmethod
Original file line number Diff line number Diff line change 1+ import asyncio
12import gc
23from collections .abc import AsyncGenerator , Iterable
34from copy import deepcopy
@@ -86,23 +87,23 @@ async def extract_content(
8687 renderer = renderer ,
8788 )
8889 for doc in docs :
89- yield _process_doc (doc , converter , output_format , output_path )
90+ yield await _process_doc (doc , converter , output_format , output_path )
9091
9192 @classmethod
9293 def _from_config (cls , config : MarkerPipelineConfig ) -> Self :
9394 return cls (config .config )
9495
9596
9697@report_recoverable_errors (_MARKER_CONVERSION_ERRORS )
97- def _process_doc (
98+ async def _process_doc (
9899 doc : InputDoc ,
99100 converter : "PdfConverter" ,
100101 output_format : OutputFormat ,
101102 output_path : Path ,
102103) -> Result :
103104 from marker .output import text_from_rendered # noqa: PLC0415
104105
105- rendered = converter ( str (doc .path ))
106+ rendered = await asyncio . to_thread ( converter , str (doc .path ))
106107 content , _ , images = text_from_rendered (rendered )
107108 match output_format :
108109 case OutputFormat .MARKDOWN :
You can’t perform that action at this time.
0 commit comments