Christopher Tan commited on
Commit
05e89fc
·
1 Parent(s): 2fb15e2

prevented stdout interfering without workers

Browse files
Files changed (1) hide show
  1. inference_openpi.py +23 -4
inference_openpi.py CHANGED
@@ -535,12 +535,31 @@ def main():
535
  continue
536
 
537
  try:
538
- print(f"DEBUG: Starting inference for task: {request.get('task_name', 'unknown')}", file=sys.stderr, flush=True)
539
- result = run_inference(request)
540
- print(f"DEBUG: Inference completed, sending result", file=sys.stderr, flush=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  result_json = json.dumps(result)
542
  print(result_json, flush=True)
543
- print(f"DEBUG: Result sent successfully", file=sys.stderr, flush=True)
544
  except Exception as e:
545
  # Error during inference - send error response as JSON
546
  import traceback
 
535
  continue
536
 
537
  try:
538
+ task_name = request.get('task_name', 'unknown')
539
+ print(f"DEBUG: Starting inference for task: {task_name}", file=sys.stderr, flush=True)
540
+
541
+ # Redirect stdout temporarily to capture any output from the environment
542
+ # This prevents environment output from interfering with our JSON protocol
543
+ import io
544
+ from contextlib import redirect_stdout
545
+
546
+ # Capture any stdout from the environment during inference
547
+ stdout_capture = io.StringIO()
548
+ try:
549
+ with redirect_stdout(stdout_capture):
550
+ result = run_inference(request)
551
+ finally:
552
+ # Check if anything was printed to stdout (this shouldn't happen, but log it if it does)
553
+ captured_output = stdout_capture.getvalue()
554
+ if captured_output:
555
+ print(f"⚠️ WARNING: Environment printed to stdout during inference: {repr(captured_output[:500])}", file=sys.stderr, flush=True)
556
+ # If we captured output, it means something printed to stdout
557
+ # This could interfere with our JSON protocol, so log it
558
+
559
+ print(f"DEBUG: Inference completed for {task_name}, sending result", file=sys.stderr, flush=True)
560
  result_json = json.dumps(result)
561
  print(result_json, flush=True)
562
+ print(f"DEBUG: Result sent successfully for {task_name}", file=sys.stderr, flush=True)
563
  except Exception as e:
564
  # Error during inference - send error response as JSON
565
  import traceback