Srevarshan1502 commited on
Commit
1f9ec6b
·
verified ·
1 Parent(s): 157adb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -384,7 +384,7 @@ class SecurePythonExecutor:
384
  print(f"DEBUG: run_with_timeout called. Client: {websocket_io.websocket.client}")
385
 
386
  # Define the synchronous target function to be run in the executor thread
387
- def _execute_in_thread_test2(): # Renamed to test2 for clarity
388
  nonlocal result
389
  original_stdin = sys.stdin
390
  original_stdout = sys.stdout
@@ -396,7 +396,7 @@ class SecurePythonExecutor:
396
  print(f"DEBUG: Executor thread '{threading.current_thread().name}' started. IO redirected.")
397
  print("DEBUG: This should now go via websocket_io.write!")
398
 
399
- # We are still not calling exec here, just testing sys.stdout print
400
  print("Hello from redirected stdout!")
401
 
402
  result['success'] = True
@@ -416,9 +416,8 @@ class SecurePythonExecutor:
416
  loop = asyncio.get_running_loop()
417
  try:
418
  print(f"DEBUG: Scheduling _execute_in_thread_test2 in executor with timeout {self.timeout}s.")
419
- # Run the synchronous _execute_in_thread_test2 in a separate thread
420
  await asyncio.wait_for(
421
- loop.run_in_executor(None, _execute_in_thread_test2), # Changed to _execute_in_thread_test2
422
  timeout=self.timeout
423
  )
424
  print("DEBUG: _execute_in_thread_test2 completed via executor.")
@@ -429,9 +428,8 @@ class SecurePythonExecutor:
429
  try:
430
  await websocket_io.write(f"Error: {result['error']}\n")
431
  except Exception:
432
- pass # Ignore if websocket is already closed
433
  except Exception as e:
434
- # This catches exceptions from _execute_in_thread_test2 that propagate up
435
  print(f"ERROR: Unexpected exception from executor: {e}")
436
  result['error'] = f"Unexpected executor error: {type(e).__name__}: {str(e)}"
437
  result['success'] = False
 
384
  print(f"DEBUG: run_with_timeout called. Client: {websocket_io.websocket.client}")
385
 
386
  # Define the synchronous target function to be run in the executor thread
387
+ def _execute_in_thread_test2(): # Using Test 2 to test sys redirection
388
  nonlocal result
389
  original_stdin = sys.stdin
390
  original_stdout = sys.stdout
 
396
  print(f"DEBUG: Executor thread '{threading.current_thread().name}' started. IO redirected.")
397
  print("DEBUG: This should now go via websocket_io.write!")
398
 
399
+ # Test print to new sys.stdout
400
  print("Hello from redirected stdout!")
401
 
402
  result['success'] = True
 
416
  loop = asyncio.get_running_loop()
417
  try:
418
  print(f"DEBUG: Scheduling _execute_in_thread_test2 in executor with timeout {self.timeout}s.")
 
419
  await asyncio.wait_for(
420
+ loop.run_in_executor(None, _execute_in_thread_test2), # Call _execute_in_thread_test2
421
  timeout=self.timeout
422
  )
423
  print("DEBUG: _execute_in_thread_test2 completed via executor.")
 
428
  try:
429
  await websocket_io.write(f"Error: {result['error']}\n")
430
  except Exception:
431
+ pass
432
  except Exception as e:
 
433
  print(f"ERROR: Unexpected exception from executor: {e}")
434
  result['error'] = f"Unexpected executor error: {type(e).__name__}: {str(e)}"
435
  result['success'] = False