Spaces:
Running
Running
Update tests.py
Browse files
tests.py
CHANGED
@@ -9,7 +9,8 @@ import openpyxl
|
|
9 |
import shutil
|
10 |
from google import genai
|
11 |
import pexpect
|
12 |
-
|
|
|
13 |
client = genai.Client(api_key="AIzaSyDtP05TyoIy9j0uPL7_wLEhgQEE75AZQSc")
|
14 |
source_dir = "/app/uploads/temp"
|
15 |
destination_dir = "/app/code_interpreter"
|
@@ -93,6 +94,19 @@ TOKEN = "5182224145:AAEjkSlPqV-Q3rH8A9X8HfCDYYEQ44v_qy0"
|
|
93 |
chat_id = "5075390513"
|
94 |
from requests_futures.sessions import FuturesSession
|
95 |
session = FuturesSession()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
def run(cmd, timeout_sec,forever_cmd):
|
98 |
global Parent
|
@@ -108,16 +122,10 @@ def run(cmd, timeout_sec,forever_cmd):
|
|
108 |
child = pexpect.spawn("bash")
|
109 |
output=""
|
110 |
command="cd /app/code_interpreter/ && "+cmd
|
111 |
-
child.sendline('su root')
|
112 |
-
print(child.readline().decode())
|
113 |
-
child.sendline('password')
|
114 |
-
print(child.readline().decode())
|
115 |
-
print(child.readline().decode())
|
116 |
|
117 |
child.sendline('PROMPT_COMMAND="echo END"')
|
118 |
child.readline().decode()
|
119 |
child.readline().decode()
|
120 |
-
child.readline().decode()
|
121 |
|
122 |
child.sendline(command)
|
123 |
|
@@ -317,9 +325,12 @@ def run_shell_command(cmd:str,forever_cmd:str) -> dict:
|
|
317 |
- ``'output'`` (str): The captured standard output (stdout) and potentially
|
318 |
standard error (stderr) from the command.
|
319 |
"""
|
|
|
|
|
320 |
transfer_files()
|
321 |
transfer_files2()
|
322 |
-
|
|
|
323 |
return {"output":output}
|
324 |
|
325 |
|
|
|
9 |
import shutil
|
10 |
from google import genai
|
11 |
import pexpect
|
12 |
+
stdout=""
|
13 |
+
stderr=""
|
14 |
client = genai.Client(api_key="AIzaSyDtP05TyoIy9j0uPL7_wLEhgQEE75AZQSc")
|
15 |
source_dir = "/app/uploads/temp"
|
16 |
destination_dir = "/app/code_interpreter"
|
|
|
94 |
chat_id = "5075390513"
|
95 |
from requests_futures.sessions import FuturesSession
|
96 |
session = FuturesSession()
|
97 |
+
from subprocess import Popen, PIPE
|
98 |
+
import shlex
|
99 |
+
from threading import Timer
|
100 |
+
def run2(cmd, timeout_sec,forever_cmd):
|
101 |
+
global stdout
|
102 |
+
global stderr
|
103 |
+
proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE,cwd="/app/code_interpreter/")
|
104 |
+
timer = Timer(timeout_sec, proc.kill)
|
105 |
+
try:
|
106 |
+
timer.start()
|
107 |
+
stdout, stderr = proc.communicate()
|
108 |
+
finally:
|
109 |
+
timer.cancel()
|
110 |
|
111 |
def run(cmd, timeout_sec,forever_cmd):
|
112 |
global Parent
|
|
|
122 |
child = pexpect.spawn("bash")
|
123 |
output=""
|
124 |
command="cd /app/code_interpreter/ && "+cmd
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
child.sendline('PROMPT_COMMAND="echo END"')
|
127 |
child.readline().decode()
|
128 |
child.readline().decode()
|
|
|
129 |
|
130 |
child.sendline(command)
|
131 |
|
|
|
325 |
- ``'output'`` (str): The captured standard output (stdout) and potentially
|
326 |
standard error (stderr) from the command.
|
327 |
"""
|
328 |
+
global stderr
|
329 |
+
global stdout
|
330 |
transfer_files()
|
331 |
transfer_files2()
|
332 |
+
run2(cmd, 300,forever_cmd)
|
333 |
+
output = str(stdout)+str(stderr)
|
334 |
return {"output":output}
|
335 |
|
336 |
|