|
@@ -12,11 +12,22 @@ if "app" != constants.CompileVars.APP:
|
|
|
|
|
|
app_module = get_app(reload=False)
|
|
|
app = getattr(app_module, constants.CompileVars.APP)
|
|
|
-compile_future = ThreadPoolExecutor(max_workers=1).submit(app.compile_)
|
|
|
-compile_future.add_done_callback(
|
|
|
- # Force background compile errors to print eagerly
|
|
|
- lambda f: f.result()
|
|
|
-)
|
|
|
+_executor = ThreadPoolExecutor(max_workers=1)
|
|
|
+
|
|
|
+
|
|
|
+def _done(executor: ThreadPoolExecutor):
|
|
|
+ def _cb(f):
|
|
|
+ # Do not leak file handles from the executor itself
|
|
|
+ executor.shutdown(wait=False)
|
|
|
+ # Force background compile errors to print eagerly
|
|
|
+ print("compile done", f.result(), executor)
|
|
|
+
|
|
|
+ return _cb
|
|
|
+
|
|
|
+
|
|
|
+compile_future = _executor.submit(app.compile_)
|
|
|
+compile_future.add_done_callback(_done(_executor))
|
|
|
+
|
|
|
# Wait for the compile to finish in prod mode to ensure all optional endpoints are mounted.
|
|
|
if is_prod_mode():
|
|
|
compile_future.result()
|
|
@@ -24,6 +35,8 @@ if is_prod_mode():
|
|
|
# ensure only "app" is exposed.
|
|
|
del app_module
|
|
|
del compile_future
|
|
|
+del _done
|
|
|
+del _executor
|
|
|
del get_app
|
|
|
del get_compiled_app
|
|
|
del is_prod_mode
|