Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,8 @@ import time
|
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
| 8 |
|
| 9 |
-
def run_pcbasic_code(code, timeout=
|
| 10 |
-
"""Executa o código PCBasic e captura saída gráfica
|
| 11 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 12 |
code_path = os.path.join(tmpdir, "code.bas")
|
| 13 |
img_path = os.path.join(tmpdir, "output.png")
|
|
@@ -15,10 +15,9 @@ def run_pcbasic_code(code, timeout=30):
|
|
| 15 |
with open(code_path, "w") as f:
|
| 16 |
f.write(code)
|
| 17 |
|
| 18 |
-
# Usar framebuffer virtual para captura de tela
|
| 19 |
env = os.environ.copy()
|
| 20 |
env["SDL_VIDEODRIVER"] = "dummy"
|
| 21 |
-
env["SDL_FBDEV"] = "/dev/fb0"
|
| 22 |
|
| 23 |
try:
|
| 24 |
process = subprocess.run(
|
|
@@ -32,20 +31,16 @@ def run_pcbasic_code(code, timeout=30):
|
|
| 32 |
img_path
|
| 33 |
],
|
| 34 |
env=env,
|
| 35 |
-
timeout=timeout,
|
| 36 |
capture_output=True
|
| 37 |
)
|
| 38 |
|
| 39 |
-
# Capturar saída de texto
|
| 40 |
text_output = process.stdout.decode('utf-8', errors='replace')
|
| 41 |
-
|
| 42 |
-
# Verificar se imagem foi criada
|
| 43 |
if os.path.exists(img_path):
|
| 44 |
img = Image.open(img_path)
|
| 45 |
return text_output, img
|
| 46 |
else:
|
| 47 |
return text_output, None
|
| 48 |
-
|
| 49 |
except subprocess.TimeoutExpired:
|
| 50 |
return "Erro: Tempo limite de execução excedido", None
|
| 51 |
except Exception as e:
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
| 8 |
|
| 9 |
+
def run_pcbasic_code(code, timeout=60): # Timeout aumentado
|
| 10 |
+
"""Executa o código PCBasic e captura saída gráfica"""
|
| 11 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 12 |
code_path = os.path.join(tmpdir, "code.bas")
|
| 13 |
img_path = os.path.join(tmpdir, "output.png")
|
|
|
|
| 15 |
with open(code_path, "w") as f:
|
| 16 |
f.write(code)
|
| 17 |
|
|
|
|
| 18 |
env = os.environ.copy()
|
| 19 |
env["SDL_VIDEODRIVER"] = "dummy"
|
| 20 |
+
env["SDL_FBDEV"] = "/dev/fb0"
|
| 21 |
|
| 22 |
try:
|
| 23 |
process = subprocess.run(
|
|
|
|
| 31 |
img_path
|
| 32 |
],
|
| 33 |
env=env,
|
| 34 |
+
timeout=timeout, # Usar timeout ajustado
|
| 35 |
capture_output=True
|
| 36 |
)
|
| 37 |
|
|
|
|
| 38 |
text_output = process.stdout.decode('utf-8', errors='replace')
|
|
|
|
|
|
|
| 39 |
if os.path.exists(img_path):
|
| 40 |
img = Image.open(img_path)
|
| 41 |
return text_output, img
|
| 42 |
else:
|
| 43 |
return text_output, None
|
|
|
|
| 44 |
except subprocess.TimeoutExpired:
|
| 45 |
return "Erro: Tempo limite de execução excedido", None
|
| 46 |
except Exception as e:
|