rbbt-util 5.44.1 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +2 -2
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +9 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +27 -17
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +11 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +40 -2
@@ -1,386 +1,389 @@
|
|
1
|
-
require 'rbbt/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
rescue
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
Log.debug "Joined process #{pid} of queue #{Process.pid}
|
167
|
-
processes.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
Log.low "
|
174
|
-
|
175
|
-
Log.
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
rescue
|
243
|
-
Log.low "
|
244
|
-
raise $!
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
raise
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
Log.
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
q.
|
385
|
-
|
386
|
-
end
|
1
|
+
require 'rbbt/refactor'
|
2
|
+
Rbbt.require_instead 'scout/work_queue'
|
3
|
+
require_relative 'processes/refactor'
|
4
|
+
#require 'rbbt/util/concurrency/processes/worker'
|
5
|
+
#require 'rbbt/util/concurrency/processes/socket'
|
6
|
+
#
|
7
|
+
#class RbbtProcessQueue
|
8
|
+
#
|
9
|
+
# attr_accessor :num_processes, :queue, :process_monitor, :cleanup, :join, :reswpan, :offset
|
10
|
+
# def initialize(num_processes, cleanup = nil, join = nil, reswpan = nil, offset = false)
|
11
|
+
# @num_processes = num_processes
|
12
|
+
# @cleanup = cleanup
|
13
|
+
# @join = join
|
14
|
+
# @respawn = reswpan
|
15
|
+
# @offset = offset
|
16
|
+
# @queue = RbbtProcessSocket.new
|
17
|
+
#
|
18
|
+
# key = "/" << rand(1000000000).to_s << '.' << Process.pid.to_s;
|
19
|
+
# @sem = key + '.process'
|
20
|
+
# Log.debug "Creating process semaphore: #{@sem}"
|
21
|
+
# RbbtSemaphore.create_semaphore(@sem,1)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# ABORT_SIGNAL = :INT
|
26
|
+
# CLOSE_SIGNAL = :PIPE
|
27
|
+
#
|
28
|
+
# attr_accessor :callback, :callback_queue, :callback_thread
|
29
|
+
# def callback(&block)
|
30
|
+
# if block_given?
|
31
|
+
#
|
32
|
+
# @callback = block
|
33
|
+
#
|
34
|
+
# @callback_queue = RbbtProcessSocket.new
|
35
|
+
#
|
36
|
+
# else
|
37
|
+
# @callback, @callback_queue, @callback_thread = nil, nil, nil
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def init_master
|
42
|
+
# RbbtSemaphore.wait_semaphore(@sem)
|
43
|
+
# @master_pid = Process.fork do
|
44
|
+
# @close_up = false
|
45
|
+
# processes_initiated = false
|
46
|
+
# processes = []
|
47
|
+
# process_mutex = Mutex.new
|
48
|
+
#
|
49
|
+
# Signal.trap(CLOSE_SIGNAL) do
|
50
|
+
# if ! @closing_thread
|
51
|
+
# @close_up = true
|
52
|
+
# Misc.insist([0,0.01,0.1,0.2,0.5]) do
|
53
|
+
# if ! @manager_thread
|
54
|
+
# Thread.pass
|
55
|
+
# raise "Manager thread for #{Process.pid} not found yet"
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# if @manager_thread.alive?
|
59
|
+
# raise "Manager thread for #{Process.pid} not working yet" unless @manager_thread["working"]
|
60
|
+
# @manager_thread.raise TryAgain
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# Signal.trap(:USR1) do
|
67
|
+
# @count += 1
|
68
|
+
# @manager_thread.raise TryAgain
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# Signal.trap(:USR2) do
|
72
|
+
# @count -= 1
|
73
|
+
# @manager_thread.raise TryAgain
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# Signal.trap(ABORT_SIGNAL) do
|
77
|
+
# @abort_monitor = true
|
78
|
+
# @monitor_thread.raise Aborted if @monitor_thread && @monitor_thread.alive?
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# if @callback_queue
|
82
|
+
# Open.purge_pipes(@queue.swrite, @queue.sread, @callback_queue.swrite)
|
83
|
+
# else
|
84
|
+
# Open.purge_pipes(@queue.swrite, @queue.sread)
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# @total = 0
|
88
|
+
# @count = 0
|
89
|
+
#
|
90
|
+
# @manager_thread = Thread.new do
|
91
|
+
# while true
|
92
|
+
# break if processes_initiated && processes.empty? && (@monitor_thread && ! @monitor_thread.alive?)
|
93
|
+
# begin
|
94
|
+
# Thread.current["working"] = true
|
95
|
+
# if @close_up
|
96
|
+
# Thread.handle_interrupt(TryAgain => :never) do
|
97
|
+
# Log.debug "Closing up process queue #{Process.pid}"
|
98
|
+
# @count = 0
|
99
|
+
# @closing_thread = Thread.new do
|
100
|
+
# Thread.handle_interrupt(TryAgain => :never) do
|
101
|
+
# Log.debug "Pushing closed stream #{Process.pid}"
|
102
|
+
# while true
|
103
|
+
# @queue.push ClosedStream.new unless @queue.cleaned
|
104
|
+
# break if processes_initiated && processes.empty?
|
105
|
+
# end unless processes_initiated && processes.empty?
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
# @close_up = false
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# begin
|
113
|
+
# sleep 3
|
114
|
+
# rescue TryAgain
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# raise TryAgain if @close_up
|
118
|
+
#
|
119
|
+
# process_mutex.synchronize do
|
120
|
+
# Thread.handle_interrupt(TryAgain => :never) do
|
121
|
+
# while @count > 0
|
122
|
+
# @count -= 1
|
123
|
+
# @total += 1
|
124
|
+
# processes << RbbtProcessQueueWorker.new(@queue, @callback_queue, @cleanup, @respawn, (@offset ? @total : false), &@init_block)
|
125
|
+
# Log.warn "Added process #{processes.last.pid} to #{Process.pid} (#{processes.length})"
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# while @count < 0
|
129
|
+
# @count += 1
|
130
|
+
# @total -= 1
|
131
|
+
# next unless processes.length > 1
|
132
|
+
# last = processes.reject{|p| p.stopping }.last
|
133
|
+
# last.stop
|
134
|
+
# Log.warn "Removed process #{last.pid} from #{Process.pid} (#{processes.length})"
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
# rescue TryAgain
|
139
|
+
# retry
|
140
|
+
# rescue Aborted
|
141
|
+
# Log.low "Aborting manager thread #{Process.pid}"
|
142
|
+
# raise $!
|
143
|
+
# rescue Exception
|
144
|
+
# raise Exception
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
# Log.low "Manager thread stopped #{Process.pid}"
|
148
|
+
# end
|
149
|
+
#
|
150
|
+
# @callback_queue.close_read if @callback_queue
|
151
|
+
#
|
152
|
+
# num_processes.to_i.times do |i|
|
153
|
+
# @total += 1
|
154
|
+
# process_mutex.synchronize do
|
155
|
+
# processes << RbbtProcessQueueWorker.new(@queue, @callback_queue, @cleanup, @respawn, (@offset ? @total : false), &@init_block)
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# processes_initiated = true
|
160
|
+
#
|
161
|
+
# @monitor_thread = Thread.new do
|
162
|
+
# begin
|
163
|
+
# while processes.any?
|
164
|
+
# raise Aborted if @abort_monitor
|
165
|
+
# #processes[0].join
|
166
|
+
# #Log.debug "Joined process #{processes[0].pid} of queue #{Process.pid}"
|
167
|
+
# #processes.shift
|
168
|
+
# pid, status = Process.wait2
|
169
|
+
# Log.debug "Joined process #{pid} of queue #{Process.pid} (status: #{status})"
|
170
|
+
# processes.reject!{|p| p.pid == pid}
|
171
|
+
# raise ProcessFailed.new pid if not status.success?
|
172
|
+
# end
|
173
|
+
# Log.low "All processes completed #{Process.pid}"
|
174
|
+
# rescue Aborted
|
175
|
+
# Log.exception $!
|
176
|
+
# Log.low "Aborting process monitor #{Process.pid}"
|
177
|
+
# processes.each{|p| p.abort_and_join}
|
178
|
+
# Log.low "Processes aborted #{Process.pid}"
|
179
|
+
# processes.clear
|
180
|
+
#
|
181
|
+
# @manager_thread.raise Aborted if @manager_thread.alive?
|
182
|
+
# raise Aborted, "Aborted monitor thread"
|
183
|
+
# rescue Exception
|
184
|
+
# Log.low "Process monitor exception [#{Process.pid}]: #{$!.message}"
|
185
|
+
# processes.each{|p| p.abort_and_join}
|
186
|
+
# Log.low "Processes aborted for monitor #{Process.pid}"
|
187
|
+
# processes.clear
|
188
|
+
#
|
189
|
+
# @manager_thread.report_on_exception = false
|
190
|
+
# @manager_thread.raise $! if @manager_thread.alive?
|
191
|
+
# raise Aborted, "Aborted monitor thread with exception"
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
# @monitor_thread.report_on_exception = false
|
195
|
+
#
|
196
|
+
# RbbtSemaphore.post_semaphore(@sem)
|
197
|
+
#
|
198
|
+
# Log.low "Process monitor #{Process.pid} joining threads"
|
199
|
+
# begin
|
200
|
+
# @monitor_thread.join
|
201
|
+
# @manager_thread.raise TryAgain if @manager_thread.alive?
|
202
|
+
# @manager_thread.join
|
203
|
+
# @callback_queue.push ClosedStream.new if @callback_queue
|
204
|
+
# rescue Exception
|
205
|
+
# Kernel.exit -1
|
206
|
+
# end
|
207
|
+
# Log.low "Process monitor #{Process.pid} threads joined successfully, now exit"
|
208
|
+
#
|
209
|
+
# Kernel.exit 0
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# @queue.close_read
|
213
|
+
# Log.info "Cpu process #{@master_pid} with #{num_processes} workers."
|
214
|
+
# Log.low "Signal #{@master_pid} USR1/USR2 (#10/#12) to increase/decrease workers."
|
215
|
+
# end
|
216
|
+
#
|
217
|
+
# def init(&block)
|
218
|
+
# @init_block = block
|
219
|
+
#
|
220
|
+
# init_master
|
221
|
+
#
|
222
|
+
# RbbtSemaphore.synchronize(@sem) do
|
223
|
+
# @callback_thread = Thread.new do
|
224
|
+
# begin
|
225
|
+
# loop do
|
226
|
+
# p = @callback_queue.pop unless @callback_queue.cleaned
|
227
|
+
#
|
228
|
+
# if Exception === p or (Array === p and Exception === p.first)
|
229
|
+
# e = Array === p ? p.first : p
|
230
|
+
# Log.low "Callback recieved exception from worker: #{e.message}" unless Aborted === e or ClosedStream === e
|
231
|
+
# raise e
|
232
|
+
# end
|
233
|
+
#
|
234
|
+
# if @callback.arity == 0
|
235
|
+
# @callback.call
|
236
|
+
# else
|
237
|
+
# @callback.call p
|
238
|
+
# end
|
239
|
+
# end
|
240
|
+
# rescue ClosedStream
|
241
|
+
# Log.low "Callback thread closing"
|
242
|
+
# rescue Aborted
|
243
|
+
# Log.low "Callback thread aborted"
|
244
|
+
# raise $!
|
245
|
+
# rescue Exception
|
246
|
+
# Log.low "Exception captured in callback: #{$!.message}"
|
247
|
+
# raise $!
|
248
|
+
# end
|
249
|
+
# end if @callback_queue
|
250
|
+
#
|
251
|
+
# @callback_thread.report_on_exception = false if @callback_thread
|
252
|
+
#
|
253
|
+
# end
|
254
|
+
#
|
255
|
+
# end
|
256
|
+
#
|
257
|
+
# def add_process
|
258
|
+
# Process.kill :USR1, @master_pid
|
259
|
+
# end
|
260
|
+
#
|
261
|
+
# def remove_process
|
262
|
+
# Process.kill :USR2, @master_pid
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# def _join
|
266
|
+
# error = :redo
|
267
|
+
# begin
|
268
|
+
# pid, @status = Process.waitpid2 @master_pid unless @status
|
269
|
+
# error = true unless @status.success?
|
270
|
+
# begin
|
271
|
+
# @callback_thread.join if @callback_thread
|
272
|
+
# raise ProcessFailed.new @master_pid unless @status.success?
|
273
|
+
# rescue
|
274
|
+
# exception = $!
|
275
|
+
# raise $!
|
276
|
+
# end
|
277
|
+
# error = false
|
278
|
+
# rescue Aborted, Interrupt
|
279
|
+
# exception = $!
|
280
|
+
# Log.exception $!
|
281
|
+
# error = true
|
282
|
+
# if @aborted
|
283
|
+
# raise $!
|
284
|
+
# else
|
285
|
+
# self.abort
|
286
|
+
# Log.high "Process queue #{@master_pid} aborted"
|
287
|
+
# retry
|
288
|
+
# end
|
289
|
+
# rescue Errno::ESRCH, Errno::ECHILD
|
290
|
+
# retry if Misc.pid_exists? @master_pid
|
291
|
+
# error = ! @status.success?
|
292
|
+
# ensure
|
293
|
+
# begin
|
294
|
+
# begin
|
295
|
+
# self.abort
|
296
|
+
# ensure
|
297
|
+
# _join
|
298
|
+
# end if error == :redo
|
299
|
+
#
|
300
|
+
# begin
|
301
|
+
# @callback_thread.join
|
302
|
+
# rescue Exception
|
303
|
+
# end
|
304
|
+
#
|
305
|
+
# Log.medium "Joining process queue #{"(error) " if error}#{@master_pid} #{@join}"
|
306
|
+
# begin
|
307
|
+
# if @join
|
308
|
+
# if @join.arity == 1
|
309
|
+
# @join.call(error)
|
310
|
+
# else
|
311
|
+
# @join.call
|
312
|
+
# end
|
313
|
+
# end
|
314
|
+
# end
|
315
|
+
# ensure
|
316
|
+
# self.clean
|
317
|
+
# end
|
318
|
+
#
|
319
|
+
# if exception
|
320
|
+
# raise exception
|
321
|
+
# else
|
322
|
+
# raise "Process queue #{@master_pid} failed"
|
323
|
+
# end if error
|
324
|
+
# end
|
325
|
+
# end
|
326
|
+
#
|
327
|
+
# def close_up_queue
|
328
|
+
# begin
|
329
|
+
# RbbtSemaphore.synchronize(@sem) do
|
330
|
+
# Process.kill CLOSE_SIGNAL, @master_pid
|
331
|
+
# end
|
332
|
+
# rescue Errno::ECHILD, Errno::ESRCH
|
333
|
+
# Log.debug "Cannot kill (CLOSE) #{@master_pid}: #{$!.message}"
|
334
|
+
# end if Misc.pid_exists? @master_pid
|
335
|
+
# end
|
336
|
+
#
|
337
|
+
# def join
|
338
|
+
# close_up_queue
|
339
|
+
#
|
340
|
+
# _join
|
341
|
+
# end
|
342
|
+
#
|
343
|
+
# def _abort
|
344
|
+
# begin
|
345
|
+
# Log.warn "Aborting process queue #{@master_pid}"
|
346
|
+
# Process.kill ABORT_SIGNAL, @master_pid
|
347
|
+
# rescue Errno::ECHILD, Errno::ESRCH
|
348
|
+
# Log.debug "Cannot abort #{@master_pid}: #{$!.message}"
|
349
|
+
# end
|
350
|
+
# end
|
351
|
+
#
|
352
|
+
# def abort
|
353
|
+
# _abort
|
354
|
+
# @callback_thread.raise(Aborted.new) if @callback_thread and @callback_thread.alive?
|
355
|
+
# @aborted = true
|
356
|
+
# begin
|
357
|
+
# _join
|
358
|
+
# rescue
|
359
|
+
# end
|
360
|
+
# end
|
361
|
+
#
|
362
|
+
# def clean
|
363
|
+
# RbbtSemaphore.delete_semaphore(@sem)
|
364
|
+
# begin
|
365
|
+
# self.abort if Misc.pid_exists?(@master_pid)
|
366
|
+
#
|
367
|
+
# ensure
|
368
|
+
# @queue.clean if @queue
|
369
|
+
# #@callback_thread.push ClosedStream if @callback_thread && @callback_thread.alive?
|
370
|
+
# @callback_queue.clean if @callback_queue
|
371
|
+
# end
|
372
|
+
# end
|
373
|
+
#
|
374
|
+
#
|
375
|
+
# def process(*e)
|
376
|
+
# begin
|
377
|
+
# @queue.push e
|
378
|
+
# rescue Errno::EPIPE
|
379
|
+
# raise Aborted
|
380
|
+
# end
|
381
|
+
# end
|
382
|
+
#
|
383
|
+
# def self.each(list, num = 3, &block)
|
384
|
+
# q = RbbtProcessQueue.new num
|
385
|
+
# q.init(&block)
|
386
|
+
# list.each do |elem| q.process elem end
|
387
|
+
# q.join
|
388
|
+
# end
|
389
|
+
#end
|