@mcmcjs/julia 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +0,0 @@
1
- [deps]
2
- AdvancedHMC = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d"
3
- DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
4
- FlexiChains = "4a37a8b9-6e57-4b92-8664-298d46e639f7"
5
- ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
6
- JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
7
- JuliaBUGS = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf"
8
- Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
9
- ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
10
- StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
11
- StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
12
- Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
package/dist/worker.jl DELETED
@@ -1,102 +0,0 @@
1
- # MCMC.js persistent fit worker. Keeps Turing loaded between fits so warm
2
- # re-fits skip the cold start. Listens on a Unix domain socket (ARGS[1]); each
3
- # connection carries one JSON request line and receives {"mcmcjs":"progress"}
4
- # lines followed by one final handle_request result line. A {"mcmcjs":"stop"}
5
- # request shuts the worker down; so does half an hour of idleness.
6
- include(joinpath(@__DIR__, "fitlib.jl"))
7
- using Sockets
8
-
9
- const IDLE_TIMEOUT_S = 30 * 60
10
-
11
- # True while this process still owns the socket path: another worker stealing
12
- # the path (by binding over it) changes the inode, and a worker that lost the
13
- # path must never delete its successor's socket.
14
- function owns_socket(path, ino)
15
- try
16
- return stat(path).inode == ino
17
- catch
18
- return false
19
- end
20
- end
21
-
22
- function remove_if_owned(path, ino)
23
- if owns_socket(path, ino)
24
- rm(path; force = true)
25
- rm(path * ".pid"; force = true)
26
- end
27
- end
28
-
29
- function serve(path)
30
- mkpath(dirname(path))
31
- if ispath(path)
32
- # A live worker already serving this path wins; a dead socket file is cleared.
33
- try
34
- close(Sockets.connect(path))
35
- exit(0)
36
- catch
37
- rm(path; force = true)
38
- rm(path * ".pid"; force = true)
39
- end
40
- end
41
- server = Sockets.listen(path)
42
- ino = stat(path).inode
43
- # A pidfile beside the socket lets a cancelling client kill this worker
44
- # mid-fit (it cannot answer a polite stop while busy sampling).
45
- write(path * ".pid", string(getpid()))
46
- atexit(() -> remove_if_owned(path, ino))
47
-
48
- last_activity = Ref(time())
49
- busy = Ref(false)
50
- # The watchdog task is cooperative: it gets scheduled while the main task
51
- # blocks on accept. The busy guard is belt and braces for any future
52
- # multithreaded scheduling.
53
- @async while true
54
- sleep(30)
55
- if !busy[] && time() - last_activity[] > IDLE_TIMEOUT_S
56
- remove_if_owned(path, ino)
57
- exit(0)
58
- end
59
- end
60
-
61
- while true
62
- sock = Sockets.accept(server)
63
- busy[] = true
64
- stopping = false
65
- try
66
- line = readline(sock)
67
- if isempty(strip(line))
68
- close(sock)
69
- continue
70
- end
71
- request = JSON.parse(line)
72
- if get(request, "mcmcjs", "") == "stop"
73
- stopping = true
74
- println(sock, JSON.json(Dict("ok" => true, "stopped" => true)))
75
- else
76
- PROGRESS_IO[] = sock
77
- result = try
78
- handle_request(request)
79
- finally
80
- PROGRESS_IO[] = stderr
81
- end
82
- println(sock, JSON.json(result))
83
- end
84
- close(sock)
85
- catch err
86
- try
87
- println(sock, JSON.json(Dict("ok" => false, "error" => sprint(showerror, err), "stage" => "worker")))
88
- close(sock)
89
- catch
90
- end
91
- finally
92
- busy[] = false
93
- last_activity[] = time()
94
- end
95
- if stopping
96
- remove_if_owned(path, ino)
97
- exit(0)
98
- end
99
- end
100
- end
101
-
102
- serve(ARGS[1])