author | wenzelm |
Sat, 28 Mar 2020 13:30:38 +0100 | |
changeset 71605 | f7a652732f4e |
parent 71604 | c6fa217c9d5e |
child 71607 | d97f504c8145 |
permissions | -rw-r--r-- |
43283 | 1 |
/* Title: Pure/System/isabelle_process.scala |
27949
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
3 |
|
57916 | 4 |
Isabelle process wrapper. |
27949
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
5 |
*/ |
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
6 |
|
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
8 |
|
55618 | 9 |
|
65310 | 10 |
import java.io.{File => JFile} |
11 |
||
12 |
||
57917 | 13 |
object Isabelle_Process |
14 |
{ |
|
71597 | 15 |
def apply( |
71594 | 16 |
session: Session, |
65216 | 17 |
options: Options, |
71594 | 18 |
sessions_structure: Sessions.Structure, |
71598 | 19 |
store: Sessions.Store, |
65216 | 20 |
logic: String = "", |
21 |
args: List[String] = Nil, |
|
22 |
modes: List[String] = Nil, |
|
65310 | 23 |
cwd: JFile = null, |
71604 | 24 |
env: Map[String, String] = Isabelle_System.settings()): Isabelle_Process = |
65216 | 25 |
{ |
62556
c115e69f457f
more abstract Session.start, without prover command-line;
wenzelm
parents:
62555
diff
changeset
|
26 |
val channel = System_Channel() |
c115e69f457f
more abstract Session.start, without prover command-line;
wenzelm
parents:
62555
diff
changeset
|
27 |
val process = |
57916 | 28 |
try { |
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
68209
diff
changeset
|
29 |
val channel_options = |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
68209
diff
changeset
|
30 |
options.string.update("system_channel_address", channel.address). |
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
68209
diff
changeset
|
31 |
string.update("system_channel_password", channel.password) |
71598 | 32 |
ML_Process(channel_options, sessions_structure, store, |
33 |
logic = logic, args = args, modes = modes, cwd = cwd, env = env) |
|
57916 | 34 |
} |
69572
09a6a7c04b45
more robust system channel via options that are private to the user;
wenzelm
parents:
68209
diff
changeset
|
35 |
catch { case exn @ ERROR(_) => channel.shutdown(); throw exn } |
62556
c115e69f457f
more abstract Session.start, without prover command-line;
wenzelm
parents:
62555
diff
changeset
|
36 |
process.stdin.close |
57917 | 37 |
|
71604 | 38 |
new Isabelle_Process(session, channel, process) |
57917 | 39 |
} |
57916 | 40 |
} |
71604 | 41 |
|
42 |
class Isabelle_Process private(session: Session, channel: System_Channel, process: Bash.Process) |
|
43 |
{ |
|
44 |
private val startup_error = Future.promise[String] |
|
45 |
||
46 |
session.phase_changed += |
|
47 |
Session.Consumer(getClass.getName) { |
|
48 |
case Session.Ready => |
|
49 |
startup_error.fulfill("") |
|
50 |
case Session.Terminated(result) if !result.ok && !startup_error.is_finished => |
|
71605 | 51 |
val syslog = session.syslog_content() |
52 |
val err = "Session startup failed" + (if (syslog.isEmpty) "" else ":\n" + syslog) |
|
53 |
startup_error.fulfill(err) |
|
71604 | 54 |
case _ => |
55 |
} |
|
56 |
||
57 |
def startup_join(): Unit = |
|
58 |
startup_error.join match { |
|
59 |
case "" => |
|
60 |
case msg => session.stop(); error(msg) |
|
61 |
} |
|
62 |
||
63 |
session.start(receiver => new Prover(receiver, session.xml_cache, channel, process)) |
|
64 |
} |