Skip to content

Commit f0d9840

Browse files
committed
backend/latex: introduce "killed" state (frontend only) and avoid running compile tasks if stopped
1 parent 8fcc00f commit f0d9840

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/packages/frontend/frame-editors/latex-editor/actions.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class Actions extends BaseActions<LatexEditorState> {
107107
private _last_sagetex_hash: string;
108108
private _last_syncstring_hash: number | undefined;
109109
private is_building: boolean = false;
110+
private is_stopping: boolean = false; // if true, do not continue running any compile jobs
110111
private ext: string = "tex";
111112
private knitr: boolean = false; // true, if we deal with a knitr file
112113
private filename_knitr: string; // .rnw or .rtex
@@ -725,7 +726,7 @@ export class Actions extends BaseActions<LatexEditorState> {
725726
// likely "No such process", we just ignore it
726727
} finally {
727728
// set this build log to be no longer running
728-
job.status = "completed";
729+
job.status = "killed";
729730
}
730731
}
731732
return job;
@@ -734,17 +735,23 @@ export class Actions extends BaseActions<LatexEditorState> {
734735
// This stops all known jobs with a status "running" and resets the state.
735736
async stop_build(_id?: string) {
736737
const build_logs = this.store.get("build_logs");
737-
if (build_logs) {
738-
for (const [name, job] of build_logs) {
739-
this.set_build_logs({ [name]: await this.kill(job.toJS()) });
738+
try {
739+
this.is_stopping = true;
740+
if (build_logs) {
741+
for (const [name, job] of build_logs) {
742+
// this.kill returns the job with a modified status, it's not the kill exec itself
743+
this.set_build_logs({ [name]: await this.kill(job.toJS()) });
744+
}
740745
}
746+
} finally {
747+
this.set_status("");
748+
this.is_building = false;
749+
this.is_stopping = false;
741750
}
742-
743-
this.set_status("");
744-
this.is_building = false;
745751
}
746752

747753
private async run_build(time: number, force: boolean): Promise<void> {
754+
if (this.is_stopping) return;
748755
// reset state of build_logs, since it is a fresh start
749756
this.setState({ build_logs: Map() });
750757

@@ -807,6 +814,7 @@ export class Actions extends BaseActions<LatexEditorState> {
807814
}
808815

809816
private async run_knitr(time: number, force: boolean): Promise<void> {
817+
if (this.is_stopping) return;
810818
let output: BuildLog;
811819
const status = (s) => this.set_status(`Running Knitr... ${s}`);
812820
const set_job_info = (job) => this.set_build_logs({ knitr: job });
@@ -890,6 +898,7 @@ export class Actions extends BaseActions<LatexEditorState> {
890898
force: boolean,
891899
update_pdf: boolean = true,
892900
): Promise<void> {
901+
if (this.is_stopping) return;
893902
let output: BuildLog;
894903
let build_command: string | string[];
895904
const timestamp = this.make_timestamp(time, force);
@@ -1105,6 +1114,7 @@ export class Actions extends BaseActions<LatexEditorState> {
11051114
}
11061115

11071116
async run_sagetex(time: number, force: boolean): Promise<void> {
1117+
if (this.is_stopping) return;
11081118
const status = (s) => this.set_status(`Running SageTeX... ${s}`);
11091119
const set_job_info = (job) => this.set_build_logs({ sagetex: job });
11101120
status("");
@@ -1174,6 +1184,7 @@ export class Actions extends BaseActions<LatexEditorState> {
11741184
}
11751185

11761186
async run_pythontex(time: number, force: boolean): Promise<void> {
1187+
if (this.is_stopping) return;
11771188
let output: BuildLog;
11781189
const status = (s) => this.set_status(`Running PythonTeX... ${s}`);
11791190
const set_job_info = (job) => this.set_build_logs({ pythontex: job });

src/packages/util/types/execute-code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface ExecuteCodeOutputAsync extends ExecuteCodeBase {
1616
type: "async";
1717
start: number;
1818
job_id: string;
19-
status: AsyncStatus;
19+
status: AsyncStatus | "killed"; // killed is only set by the frontend (latex)
2020
elapsed_s?: number; // how long it took, async execution
2121
pid?: number; // in case you want to kill it remotely, good to know the PID
2222
stats?: {

0 commit comments

Comments
 (0)