MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / start

Method start

src/main/java/trace/video/PythonHead.kt:25–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 lateinit var ce: Box.BiFunctionOfBoxAnd<String, Triple<Any, MutableList<String>, MutableList<Pair<Int, String>>>>
24 @JvmStatic
25 var now: Any? = JSONObject()
26 @JvmStatic
27 lateinit var head: PythonHead
28 @JvmStatic
29 var started: Boolean = false
30
31 @JvmStatic
32 fun start(box: Box, python: String, path: String, args: List<String>) {
33 if (PythonHead.started) return
34
35
36
37 ce = (box up Exec.exec)!!
38 PythonHead.box = box
39
40 if (!File(path).exists()) throw IllegalArgumentException(" can't find the path '${path}', typo?")
41 if (!File(python).exists()) throw IllegalArgumentException(" can't find the python executable '${python}', typo?")
42 if (!File(path + "/process.py").exists()) throw IllegalArgumentException(" path '${path}' exists, but doesn't contain a python head installation, typo?")
43
44 val b = ProcessBuilder()
45 b.command(listOf(python, "process.py") + args).directory(File(path)).redirectErrorStream(true)
46 val p = b.start()
47 val reader = p.inputStream.reader().buffered(5)
48
49 PythonHead.head = PythonHead()
50
51
52 Thread {
53 PythonHead.started = true
54
55 while (p.isAlive) {
56 try {
57 val rr = reader.readLine()
58
59 println("R")
60 if (rr != null && rr.trim().startsWith("{"))
61 PythonHead.now = PythonHead.head!!.readLine(rr)
62 else if (rr != null)
63 print("r " + rr)
64 Thread.sleep(2)
65 } catch (e: Exception) {
66 e.printStackTrace()

Callers

nothing calls this directly

Calls 5

FileFunction · 0.85
PythonHeadClass · 0.85
existsMethod · 0.80
readerMethod · 0.80
readLineMethod · 0.45

Tested by

no test coverage detected