File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -271,6 +271,39 @@ def main() -> None:
271271 except BaseException as e :
272272 print (f"[WARNING] Init script failed: { e } " , file = sys .stderr )
273273
274+ # On Windows, we must import numpy here on the main thread before opening stdin.
275+ # Otherwise, the import will hang, even if run as part of a task with queue="main".
276+ # See: https://github.com/numpy/numpy/issues/24290.
277+ # The best way to do that is by creating the Python service like:
278+ #
279+ # env.python().init("import numpy")
280+ #
281+ # or similar `init` script invocation.
282+ #
283+ # We check here whether the hanging conditions might be met: NumPy installed,
284+ # but not imported yet. And if so, issue a stern warning, as a kindness.
285+ try :
286+ from importlib .metadata import distributions
287+
288+ numpy_installed = any (
289+ dist .metadata ["Name" ] == "numpy" for dist in distributions ()
290+ )
291+ if numpy_installed and "numpy" not in globals ():
292+ print (
293+ "[WARNING] This environment includes numpy, but numpy was not imported via a service init script." ,
294+ file = sys .stderr ,
295+ )
296+ print (
297+ "[WARNING] If you attempt to `import numpy` in a task on Windows, the task will hang!" ,
298+ file = sys .stderr ,
299+ )
300+ print (
301+ "[WARNING] See https://github.com/apposed/appose/issues/23 for details." ,
302+ file = sys .stderr ,
303+ )
304+ except Exception :
305+ pass
306+
274307 worker .run ()
275308
276309
You can’t perform that action at this time.
0 commit comments