MogensR commited on
Commit
6d44f52
·
1 Parent(s): 00acd62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -1,40 +1,37 @@
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__":
 
1
  #!/usr/bin/env python3
2
  # app.py — process entrypoint
3
 
4
+ # 1) Fix OMP/BLAS envs early (prevents libgomp crash)
5
+ import os, sys
6
+ if not os.environ.get("OMP_NUM_THREADS", "").strip().isdigit():
7
+ os.environ["OMP_NUM_THREADS"] = "2"
 
 
 
 
 
 
8
  os.environ.setdefault("MKL_NUM_THREADS", "2")
9
  os.environ.setdefault("OPENBLAS_NUM_THREADS", "2")
10
  os.environ.setdefault("NUMEXPR_NUM_THREADS", "2")
11
 
12
+ # Make repo root importable
 
 
 
13
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
14
 
15
+ # 2) Optionally tame Torch threads early (best effort)
 
16
  try:
17
  import torch
 
18
  if os.environ.get("TORCH_NUM_THREADS") is None:
19
  torch.set_num_threads(2)
20
  if os.environ.get("TORCH_NUM_INTEROP_THREADS") is None:
21
  torch.set_num_interop_threads(2)
22
  except Exception:
 
23
  pass
24
 
25
+ # 3) Launch quiet self-check (threaded) BEFORE app UI starts
26
+ try:
27
+ from tools.self_check import launch_self_check_async
28
+ launch_self_check_async() # honors DISABLE_SELF_CHECK
29
+ except Exception as e:
30
+ # Do not fail startup if self-check wiring has issues
31
+ import logging
32
+ logging.getLogger(__name__).warning(f"Self-check launch skipped: {e}")
33
+
34
+ # 4) Now import and launch the app
35
  from core.app import main
36
 
37
  if __name__ == "__main__":