alexnasa commited on
Commit
2b6c522
·
verified ·
1 Parent(s): ec26f71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -7,37 +7,41 @@ import uuid
7
  import shutil
8
  from tqdm import tqdm
9
  import threading
10
- import psutil, os
11
-
12
- def print_open_files(tag=""):
13
- pid = os.getpid()
14
- p = psutil.Process(pid)
15
- print(f"[DEBUG] {tag} Open file descriptors:", p.num_fds())
16
-
17
- def print_process_count(tag=""):
18
- proc_count = len(psutil.pids())
19
- print(f"[DEBUG] {tag} Process count:", proc_count)
20
-
21
- def print_thread_count(tag=""):
22
- print(f"[DEBUG] {tag} Thread count:", len(threading.enumerate()))
23
 
24
- def print_ffmpeg_processes(tag=""):
25
- count = 0
26
- for p in psutil.process_iter(['name', 'cmdline']):
27
- if 'ffmpeg' in (p.info['name'] or '') or \
28
- any('ffmpeg' in (arg or '') for arg in (p.info['cmdline'] or [])):
29
- count += 1
30
- print(f"[DEBUG] {tag} FFmpeg running:", count)
31
 
32
  def debug_resources(tag=""):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  print("========== RESOURCE DEBUG", tag, "==========")
34
- print_thread_count()
35
- print_process_count()
36
- print_ffmpeg_processes()
37
- print_open_files()
38
  print("============================================")
39
 
40
-
41
  from huggingface_hub import snapshot_download, list_repo_files, hf_hub_download
42
  import importlib, site
43
 
 
7
  import shutil
8
  from tqdm import tqdm
9
  import threading
10
+ import os
11
+ import psutil
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ PROC = psutil.Process(os.getpid())
 
 
 
 
 
 
14
 
15
  def debug_resources(tag=""):
16
+ # Threads in this process
17
+ thread_count = PROC.num_threads()
18
+
19
+ # Children processes spawned by this process (recursive = include grandchildren)
20
+ children = PROC.children(recursive=True)
21
+ child_count = len(children)
22
+
23
+ # Group children by name to see what’s being spawned (ffmpeg, python, etc.)
24
+ name_counts = {}
25
+ for c in children:
26
+ try:
27
+ name = c.name()
28
+ except psutil.Error:
29
+ name = "unknown"
30
+ name_counts[name] = name_counts.get(name, 0) + 1
31
+
32
+ # File descriptors (Linux/macOS; on Windows use len(PROC.open_files()) instead)
33
+ try:
34
+ fd_count = PROC.num_fds()
35
+ except AttributeError:
36
+ fd_count = len(PROC.open_files())
37
+
38
  print("========== RESOURCE DEBUG", tag, "==========")
39
+ print("[DEBUG]", "Threads in this process:", thread_count)
40
+ print("[DEBUG]", "Child processes (recursive):", child_count)
41
+ print("[DEBUG]", "Child processes by name:", name_counts)
42
+ print("[DEBUG]", "Open file descriptors:", fd_count)
43
  print("============================================")
44
 
 
45
  from huggingface_hub import snapshot_download, list_repo_files, hf_hub_download
46
  import importlib, site
47