Make all debug prints conditional on get_debug() - suppress debug output when --debug not specified

parent e6634929
This diff is collapsed.
...@@ -27,11 +27,12 @@ import shutil ...@@ -27,11 +27,12 @@ import shutil
import json import json
import time import time
from .comm import SocketCommunicator, Message from .comm import SocketCommunicator, Message
from .config import get_comm_type, get_backend_worker_port from .config import get_comm_type, get_backend_worker_port, get_debug
def train_model(train_path, output_model, description): def train_model(train_path, output_model, description):
"""Perform training.""" """Perform training."""
print(f"DEBUG: Starting training with videotrain for output_model {output_model}") if get_debug():
print(f"DEBUG: Starting training with videotrain for output_model {output_model}")
desc_file = os.path.join(train_path, "description.txt") desc_file = os.path.join(train_path, "description.txt")
with open(desc_file, "w") as f: with open(desc_file, "w") as f:
f.write(description) f.write(description)
...@@ -39,7 +40,8 @@ def train_model(train_path, output_model, description): ...@@ -39,7 +40,8 @@ def train_model(train_path, output_model, description):
# Assume videotrain is available # Assume videotrain is available
cmd = ["python", "videotrain", train_path, "--output_dir", output_model] cmd = ["python", "videotrain", train_path, "--output_dir", output_model]
result = subprocess.run(cmd, capture_output=True, text=True) result = subprocess.run(cmd, capture_output=True, text=True)
print(f"DEBUG: Training subprocess completed with returncode {result.returncode}") if get_debug():
print(f"DEBUG: Training subprocess completed with returncode {result.returncode}")
if result.returncode == 0: if result.returncode == 0:
return "Training completed!" return "Training completed!"
else: else:
...@@ -47,7 +49,8 @@ def train_model(train_path, output_model, description): ...@@ -47,7 +49,8 @@ def train_model(train_path, output_model, description):
def worker_process(backend_type: str): def worker_process(backend_type: str):
"""Main worker process.""" """Main worker process."""
print(f"Starting Training Worker for {backend_type}...") if get_debug():
print(f"Starting Training Worker for {backend_type}...")
# Workers use TCP for interprocess communication # Workers use TCP for interprocess communication
comm = SocketCommunicator(host='127.0.0.1', port=get_backend_worker_port(), comm_type='tcp') comm = SocketCommunicator(host='127.0.0.1', port=get_backend_worker_port(), comm_type='tcp')
...@@ -60,10 +63,11 @@ def worker_process(backend_type: str): ...@@ -60,10 +63,11 @@ def worker_process(backend_type: str):
while True: while True:
try: try:
message = comm.receive_message() message = comm.receive_message()
if message: if message and get_debug():
print(f"DEBUG: Worker {os.getpid()} received message: {message}") print(f"DEBUG: Worker {os.getpid()} received message: {message}")
if message and message.msg_type == 'train_request': if message and message.msg_type == 'train_request':
print(f"DEBUG: Worker received train_request: {message.msg_id}") if get_debug():
print(f"DEBUG: Worker received train_request: {message.msg_id}")
data = message.data data = message.data
output_model = data.get('output_model', './VideoModel') output_model = data.get('output_model', './VideoModel')
description = data.get('description', '') description = data.get('description', '')
...@@ -71,16 +75,20 @@ def worker_process(backend_type: str): ...@@ -71,16 +75,20 @@ def worker_process(backend_type: str):
if train_dir and os.path.isdir(train_dir): if train_dir and os.path.isdir(train_dir):
print(f"PROGRESS: Job {message.msg_id} accepted - Starting training") print(f"PROGRESS: Job {message.msg_id} accepted - Starting training")
print(f"DEBUG: Starting training for job {message.msg_id}") if get_debug():
print(f"DEBUG: Starting training for job {message.msg_id}")
result = train_model(train_dir, output_model, description) result = train_model(train_dir, output_model, description)
print(f"PROGRESS: Job {message.msg_id} - 100% - Training completed") print(f"PROGRESS: Job {message.msg_id} - 100% - Training completed")
print(f"DEBUG: Training completed for job {message.msg_id}") if get_debug():
print(f"DEBUG: Training completed for job {message.msg_id}")
else: else:
result = "No valid training directory provided" result = "No valid training directory provided"
print(f"DEBUG: No valid training directory for job {message.msg_id}") if get_debug():
print(f"DEBUG: No valid training directory for job {message.msg_id}")
response = Message('train_response', message.msg_id, {'message': result}) response = Message('train_response', message.msg_id, {'message': result})
print(f"DEBUG: Sending train_response for job {message.msg_id}") if get_debug():
print(f"DEBUG: Sending train_response for job {message.msg_id}")
comm.send_message(response) comm.send_message(response)
time.sleep(0.1) time.sleep(0.1)
except Exception as e: except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment