File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,18 @@ def execute_script():
141141
142142 self ._report_completion ()
143143
144+ # pre-load imports in before starting a new separate Thread.
145+ # in windows some imports (e.g. numpy) lead to the script
146+ # get stuck if loaded in separate thread
147+ block = ast .parse (script , mode = 'exec' )
148+ import_nodes = [
149+ node for node in block .body
150+ if isinstance (node , (ast .Import , ast .ImportFrom ))
151+ ]
152+ import_block = ast .Module (body = import_nodes , type_ignores = [])
153+ compiled_imports = compile (import_block , filename = "<imports>" , mode = "exec" )
154+ exec (compiled_imports , globals ())
155+
144156 # Create a thread and save a reference to it, in case its script
145157 # ends up killing the thread. This happens e.g. if it calls sys.exit.
146158 self .thread = Thread (target = execute_script , name = f"Appose-{ self .uuid } " )
You can’t perform that action at this time.
0 commit comments