1515
1616if "WDOC_DISABLE_LAZYLOADING" not in os .environ :
1717
18- def import_worker (q : Queue ):
18+ def import_worker (q : Queue , import_lock : threading . Lock ):
1919 while True :
2020 module = q .get ()
2121 if module is None :
@@ -32,25 +32,34 @@ def import_worker(q: Queue):
3232 assert first in sys .modules , f"Error when importing '{ first } '"
3333 if "Lazily-loaded" in str (sys .modules [first ]):
3434 # print(f"Module is lazy loaded so far: {first}")
35- try :
36- dir (sys .modules [first ])
37- except Exception as e :
38- print (
39- f"Error when unlazyloading module '{ first } '. Error: '{ e } '"
40- "\n You can try setting the env variable "
41- "WDOC_DISABLE_LAZYLOADING to 'true'"
42- "Don't hesitate to open an issue!"
43- )
35+ with import_lock :
36+ try :
37+ dir (sys .modules [first ])
38+ except Exception as e :
39+ print (
40+ f"Error when unlazyloading module '{ first } '. Error: '{ e } '"
41+ "\n You can try setting the env variable "
42+ "WDOC_DISABLE_LAZYLOADING to 'true'"
43+ "Don't hesitate to open an issue!"
44+ )
4445 # print(f"Unlazyloaded module: {first}")
4546
4647
4748 q = Queue ()
48- thread = threading .Thread (target = import_worker , args = (q ,), daemon = False )
49+ import_lock = threading .Lock ()
50+ thread = threading .Thread (
51+ target = import_worker ,
52+ args = (q ,import_lock ),
53+ daemon = False ,
54+ )
4955 thread .start ()
5056
5157 def threaded_loading (module : str ) -> None :
5258 q .put (module )
53- lazy_import .lazy_module (module )
59+ # for some reason enabling lazy import this way makes python hang,
60+ # except if a breakpoint is used?! Disabling for now
61+ # with import_lock:
62+ # lazy_import.lazy_module(module)
5463
5564 threaded_loading ("langchain.text_splitter" )
5665 threaded_loading ("litellm" )
0 commit comments