Skip to content

Commit b6b6514

Browse files
Add task cancellation
1 parent bf71113 commit b6b6514

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

REPL/JSON.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace REPL
1414
/-- Base structure with timeout that all command types can inherit from -/
1515
structure BaseOptions where
1616
/--
17-
Optional timeout in milliseconds. If none, no timeout will be applied.
17+
Optional soft timeout in milliseconds. If none, no timeout will be applied.
18+
If the timeout is reached, an attempt will be made to interrupt the process.
1819
-/
1920
timeout : Option Nat := none
2021

REPL/Main.lean

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,16 @@ def runWithTimeout (timeout? : Option Nat) (task : M IO α) : M IO α :=
372372
let jobTask ← IO.asTask (prio := .dedicated) (StateT.run task (← get))
373373
let timeoutTask : IO (α × State) := do
374374
IO.sleep timeout.toUInt32
375-
throw <| IO.userError s!"Operation timed out after {timeout}ms"
376-
match ← IO.waitAny [jobTask, ← IO.asTask timeoutTask] with
375+
throw <| IO.userError s!"Operation timed out"
376+
let timeoutTask ← IO.asTask timeoutTask
377+
match ← IO.waitAny [jobTask, timeoutTask] with
377378
| .ok (a, state) => do
379+
IO.cancel timeoutTask
378380
modify fun _ => state
379381
return a
380-
| .error e => throw e
382+
| .error e =>
383+
IO.cancel jobTask
384+
throw e
381385

382386
end REPL
383387

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{"env": 0}
2+
3+
{"sorries":
4+
[{"proofState": 0,
5+
"pos": {"line": 2, "column": 83},
6+
"goal":
7+
"u v : ℕ → ℕ\nh₀ : ∀ (n : ℕ), u n = 2 * n + 2\nh₁ : ∀ (n : ℕ), v n = 2 * n + 1\n⊢ ∑ k ∈ Finset.range 2003, u k - ∑ k ∈ Finset.range 2003, v k = 2003",
8+
"endPos": {"line": 2, "column": 88}}],
9+
"messages":
10+
[{"severity": "info",
11+
"pos": {"line": 2, "column": 6},
12+
"endPos": {"line": 2, "column": 7},
13+
"data":
14+
"The '∑ x in s, f x' notation is deprecated: please use '∑ x ∈ s, f x' instead:\n∑ k ∈ Finset.range 2003, u k"},
15+
{"severity": "info",
16+
"pos": {"line": 2, "column": 39},
17+
"endPos": {"line": 2, "column": 40},
18+
"data":
19+
"The '∑ x in s, f x' notation is deprecated: please use '∑ x ∈ s, f x' instead:\n∑ k ∈ Finset.range 2003, v k"},
20+
{"severity": "warning",
21+
"pos": {"line": 1, "column": 8},
22+
"endPos": {"line": 1, "column": 22},
23+
"data": "declaration uses 'sorry'"}],
24+
"env": 1}
25+
26+
{"message": "Operation timed out"}
27+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"cmd": "import Mathlib\nset_option maxHeartbeats 0\nset_option maxRecDepth 100000"}
2+
3+
{"cmd": "theorem amc12a_2003_p1 (u v : ℕ → ℕ) (h₀ : ∀ n, u n = 2 * n + 2) (h₁ : ∀ n, v n = 2 * n + 1) :\n ((∑ k in Finset.range 2003, u k) - ∑ k in Finset.range 2003, v k) = 2003 := by sorry", "env": 0}
4+
5+
{"tactic": "(\nsimp only [h₀, h₁, Finset.sum_range_succ, Finset.sum_range_zero]; rfl)", "proofState": 0, "timeout": 2000}
6+

test/timeout.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
{"proofStatus": "Completed", "proofState": 3, "goals": []}
2828

29-
{"message": "Operation timed out after 1ms"}
29+
{"message": "Operation timed out"}
3030

3131
{"message": "Unknown proof state."}
3232

0 commit comments

Comments
 (0)