Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop previous papyros execution on new debug run #5362

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/assets/javascripts/tutor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initPapyros, OFFCANVAS_ID } from "coding_scratchpad";
import { InputMode, ProgrammingLanguage } from "@dodona/papyros";
import { InputMode, ProgrammingLanguage, RunState } from "@dodona/papyros";

Check warning on line 2 in app/assets/javascripts/tutor.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/tutor.ts#L2

Added line #L2 was not covered by tests
import { BatchInputHandler } from "@dodona/papyros/dist/input/BatchInputHandler";
import { Offcanvas } from "bootstrap";
import { RunMode } from "@dodona/papyros/dist/Backend";
Expand Down Expand Up @@ -49,6 +49,16 @@
async function loadTutor(exerciseId: string, studentCode: string, statements: string, stdin: string, inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void> {
const papyros = await initPapyros(ProgrammingLanguage.Python);

if (papyros.codeRunner.getState() != RunState.Ready && papyros.codeRunner.getState() != RunState.Loading) {
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
// stop the code runner if it is running
await papyros.codeRunner.stop();

Check warning on line 54 in app/assets/javascripts/tutor.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/tutor.ts#L54

Added line #L54 was not covered by tests

// wait to make sure the code runner is stopped
while (papyros.codeRunner.getState() == RunState.Stopping) {
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
await new Promise(resolve => setTimeout(resolve, 100));

Check warning on line 58 in app/assets/javascripts/tutor.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/tutor.ts#L57-L58

Added lines #L57 - L58 were not covered by tests
}
}

papyros.setCode(studentCode);
papyros.codeRunner.inputManager.setInputMode(InputMode.Batch);
(papyros.codeRunner.inputManager.inputHandler as BatchInputHandler).batchEditor.setText(stdin);
Expand Down