Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,41 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from core.app import main
|
| 7 |
|
| 8 |
if __name__ == "__main__":
|
| 9 |
-
main()
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
# app.py — process entrypoint
|
| 3 |
+
|
| 4 |
+
# --- MUST come before any other imports (especially numpy/torch/opencv) ---
|
| 5 |
import os
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
# Sanitize OpenMP/BLAS thread envs *before* heavy libs initialize
|
| 9 |
+
omp = os.environ.get("OMP_NUM_THREADS", "")
|
| 10 |
+
if not omp.strip().isdigit():
|
| 11 |
+
# Spaces sometimes sets OMP_NUM_THREADS to an invalid string → crash in libgomp
|
| 12 |
+
os.environ["OMP_NUM_THREADS"] = "2" # safe default
|
| 13 |
+
# Reasonable defaults; adjust if you profile differently
|
| 14 |
+
os.environ.setdefault("MKL_NUM_THREADS", "2")
|
| 15 |
+
os.environ.setdefault("OPENBLAS_NUM_THREADS", "2")
|
| 16 |
+
os.environ.setdefault("NUMEXPR_NUM_THREADS", "2")
|
| 17 |
+
|
| 18 |
+
# (Optional) If you’ve seen duplicate OpenMP issues on certain bases, uncomment:
|
| 19 |
+
# os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE")
|
| 20 |
+
|
| 21 |
+
# If you want to prepend repo root to sys.path (your original behavior)
|
| 22 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 23 |
|
| 24 |
+
# Optionally set PyTorch intra-op threads early (must be before parallel work starts).
|
| 25 |
+
# We do it right after importing torch but still prior to importing the rest of the app.
|
| 26 |
+
try:
|
| 27 |
+
import torch
|
| 28 |
+
# Only set if not already configured by the environment
|
| 29 |
+
if os.environ.get("TORCH_NUM_THREADS") is None:
|
| 30 |
+
torch.set_num_threads(2)
|
| 31 |
+
if os.environ.get("TORCH_NUM_INTEROP_THREADS") is None:
|
| 32 |
+
torch.set_num_interop_threads(2)
|
| 33 |
+
except Exception:
|
| 34 |
+
# If torch isn't installed here or fails to import, ignore and continue.
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
# Now it’s safe to import the rest of the application.
|
| 38 |
from core.app import main
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
+
main()
|