Skip to content

Commit 2d69853

Browse files
committed
Make independent from backend
1 parent a1ff1f7 commit 2d69853

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

pythonwhat/local.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
from contextlib import redirect_stdout
66

77
from multiprocessing import Process, Queue
8-
from pythonbackend import CaptureErrors
9-
from pythonbackend.shell_utils import create
10-
from pythonbackend.tasks import TaskKillProcess, TaskCaptureFullOutput
11-
128
from pythonwhat.reporter import Reporter
139

10+
try:
11+
from pythonbackend.shell_utils import create
12+
from pythonbackend.tasks import TaskCaptureFullOutput
13+
14+
BACKEND_AVAILABLE = True
15+
except:
16+
BACKEND_AVAILABLE = False
17+
1418

1519
class StubShell:
1620
def __init__(self, init_code=None):
@@ -36,12 +40,27 @@ def __init__(self, code):
3640
self.code = code
3741

3842
def __call__(self, shell):
39-
raw_output, error = run_code(shell.run_code, self.code)
43+
return run_code(shell.run_code, self.code)
44+
45+
46+
class TaskKillProcess:
47+
def __call__(self, shell):
48+
return None
49+
50+
51+
class CaptureErrors:
52+
def __init__(self, output):
53+
self.output = output
54+
55+
def __enter__(self):
56+
pass
4057

41-
return raw_output, error
58+
def __exit__(self, exc_type, exception, traceback):
59+
if exc_type is not None:
60+
self.output.append({"type": "backend-error", "payload": str(exception)})
61+
return True
4262

4363

44-
# todo: merge with pythonbackend
4564
class WorkerProcess(Process):
4665
instances = []
4766

@@ -149,7 +168,7 @@ def run_single_process(pec, code, pid=None, mode="simple"):
149168
_ = process.executeTask(TaskCaptureOutput(pec))
150169
raw_stu_output, error = process.executeTask(TaskCaptureOutput(code))
151170

152-
elif mode == "full":
171+
elif mode == "full" and BACKEND_AVAILABLE:
153172
# slow
154173
process = WorkerProcess(pid)
155174
process.start()

0 commit comments

Comments
 (0)