rbbt-util 5.17.35 → 5.17.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dd1246667e1abdadb7f87df051266fe75214707
4
- data.tar.gz: 8ccd292c4188f094a27d55e239c05f0ffdd65e68
3
+ metadata.gz: 018ff5d75579a0f9063037ef20da554b396daa92
4
+ data.tar.gz: fbaa875c7332df4f9a5da2511e85df9e2a3fc938
5
5
  SHA512:
6
- metadata.gz: 8617fc351a070254930005d39835dc750ddf14aa00b261fc23013333b5e8b17349f5ab607cd2d9e36e84dff50639bfd14b507bef00f1b5c92bb5ba0ca727d1c4
7
- data.tar.gz: 3cee824334c00459ef780ea69cf75df14034c1c97d3e40aa6bf435938d5050806e3f83ffa332f8941d63eea7e039b95a94fb6c667c23ad6a6e22f5990124f49a
6
+ metadata.gz: e0b6ca146e9d06f87d73136afdbcc7f816e2ad333453310a633932f5f798ac810cbe97a1634949c8a3307c9acf35cab928f99830766c6c8cd9bcf67f8cf259e7
7
+ data.tar.gz: 8a25f98e0b3d4ed21571fc438433a2374f8903d0363663ef6f71bb4afce88af19909419122b98507af90ba86330f6125ec88930c285fa7d2013f3ceb1bd73541
@@ -66,6 +66,7 @@ module TSV
66
66
  callback, bar, join = Misc.process_options options, :callback, :bar, :join
67
67
 
68
68
  if callback
69
+ bar.init if bar
69
70
  tsv.through options[:key_field], options[:fields] do |k,v|
70
71
  begin
71
72
  callback.call yield(k,v)
@@ -74,6 +75,7 @@ module TSV
74
75
  end
75
76
  end
76
77
  else
78
+ bar.init if bar
77
79
  tsv.through options[:key_field], options[:fields] do |k,v|
78
80
  begin
79
81
  yield k,v
@@ -114,6 +116,7 @@ module TSV
114
116
  callback, bar, join = Misc.process_options options, :callback, :bar, :join
115
117
 
116
118
  if callback
119
+ bar.init if bar
117
120
  array.each do |e|
118
121
  begin
119
122
  callback.call yield(e)
@@ -122,9 +125,13 @@ module TSV
122
125
  end
123
126
  end
124
127
  else
128
+ bar.init if bar
125
129
  array.each do |e|
126
130
  begin
127
131
  yield e
132
+ rescue Exception
133
+ Log.exception $!
134
+ raise $!
128
135
  ensure
129
136
  bar.tick if bar
130
137
  end
@@ -147,6 +154,7 @@ module TSV
147
154
  end
148
155
 
149
156
  if callback
157
+ bar.init if bar
150
158
  while line = io.gets
151
159
  if line[-1] != "\n"
152
160
  while c = io.getc
@@ -161,6 +169,7 @@ module TSV
161
169
  end
162
170
  end
163
171
  else
172
+ bar.init if bar
164
173
  while line = io.gets
165
174
  begin
166
175
  yield line.strip
@@ -186,6 +195,7 @@ module TSV
186
195
  end
187
196
 
188
197
  if callback
198
+ bar.init if bar
189
199
  TSV::Parser.traverse(io, options) do |k,v|
190
200
  begin
191
201
  callback.call yield k, v
@@ -333,19 +343,22 @@ module TSV
333
343
 
334
344
  def self.traverse_cpus(num, obj, options, &block)
335
345
  begin
336
- callback, cleanup, join, respawn = Misc.process_options options, :callback, :cleanup, :join, :respawn
346
+ callback, cleanup, join, respawn, bar = Misc.process_options options, :callback, :cleanup, :join, :respawn, :bar
337
347
  respawn = true if ENV["RBBT_RESPAWN"] and ENV["RBBT_RESPAWN"] == "true"
338
348
 
339
349
  Log.low "Traversing in #{ num } cpus: #{respawn ? "respawn" : "no respawn"}"
340
350
  q = RbbtProcessQueue.new num, cleanup, join, respawn
351
+ callback = Proc.new{ bar.tick } if callback.nil? and bar
341
352
  q.callback &callback
342
353
  q.init &block
343
354
 
355
+ bar.init if bar
344
356
  traverse_obj(obj, options) do |*p|
345
357
  q.process *p
346
358
  end
347
359
 
348
360
  q.join
361
+
349
362
  rescue Interrupt, Aborted
350
363
  q.abort
351
364
  Log.medium{"Aborted traversal in CPUs for #{stream_name(obj) || Misc.fingerprint(obj)}: #{$!.backtrace*","}"}
@@ -364,6 +377,7 @@ module TSV
364
377
  raise $!
365
378
  ensure
366
379
  q.clean
380
+ Log::ProgressBar.remove_bar(bar) if bar
367
381
  end
368
382
  end
369
383
 
@@ -586,6 +600,7 @@ module TSV
586
600
  end
587
601
  end
588
602
 
603
+ bar.init if bar
589
604
  case into
590
605
  when TSV::Dumper, IO
591
606
  traverse_stream(obj, threads, cpus, options, &block)
@@ -3,7 +3,12 @@ class RbbtProcessQueue
3
3
  class RbbtProcessQueueWorker
4
4
  attr_reader :pid, :queue, :callback_queue, :cleanup, :block
5
5
 
6
- class Respawn < Exception; end
6
+ class Respawn < Exception
7
+ attr_accessor :payload
8
+ def initialize(payload)
9
+ @payload = payload
10
+ end
11
+ end
7
12
 
8
13
  def run
9
14
  begin
@@ -20,9 +25,14 @@ class RbbtProcessQueue
20
25
  p = @queue.pop
21
26
  next if p.nil?
22
27
  raise p if Exception === p
23
- raise p.first if Exception === p.first
24
- res = @block.call *p
25
- @callback_queue.push res if @callback_queue
28
+ raise p.first if Array === p and Exception === p.first
29
+ begin
30
+ res = @block.call *p
31
+ @callback_queue.push res if @callback_queue
32
+ rescue Respawn
33
+ @callback_queue.push $!.payload
34
+ raise $!
35
+ end
26
36
  raise Respawn if @stop
27
37
  end
28
38
  Kernel.exit! 0
@@ -16,6 +16,7 @@ class RbbtProcessQueue
16
16
  attr_accessor :callback, :callback_queue, :callback_thread
17
17
  def callback(&block)
18
18
  if block_given?
19
+
19
20
  @callback = block
20
21
 
21
22
  @callback_queue = RbbtProcessSocket.new
@@ -31,7 +32,11 @@ class RbbtProcessQueue
31
32
  raise e
32
33
  end
33
34
 
34
- @callback.call p
35
+ if @callback.arity == 0
36
+ @callback.call
37
+ else
38
+ @callback.call p
39
+ end
35
40
  end
36
41
  rescue Aborted
37
42
  Log.warn "Callback thread aborted"
@@ -43,6 +48,7 @@ class RbbtProcessQueue
43
48
  @process_monitor.raise $!
44
49
  raise $!
45
50
  ensure
51
+
46
52
  @callback_queue.sread.close unless @callback_queue.sread.closed?
47
53
  end
48
54
  end
@@ -80,7 +80,13 @@ module Log
80
80
 
81
81
  def report_msg
82
82
  str = Log.color :magenta, desc
83
- return str << " " << Log.color(:yellow, "waiting") if @ticks == 0
83
+ if @ticks == 0
84
+ if @max
85
+ return str << " " << Log.color(:yellow, "waiting on #{@max} - #{Process.pid}")
86
+ else
87
+ return str << " " << Log.color(:yellow, "waiting - #{Process.pid}")
88
+ end
89
+ end
84
90
  str << " " << thr_msg
85
91
  if max
86
92
  str << Log.color(:blue, " -- ") << eta_msg
@@ -101,7 +107,11 @@ module Log
101
107
  bars = BARS
102
108
  print(io, Log.color(:yellow, "...Progress\n"))
103
109
  bars.sort_by{|b| b.depth }.reverse.each do |bar|
104
- print(io, Log.color(:yellow ,bar.report_msg) << "\n")
110
+ if SILENCED.include? bar
111
+ print(io, Log.color(:yellow ,bar.report_msg) << "\n")
112
+ else
113
+ print(io, "\n")
114
+ end
105
115
  end
106
116
  else
107
117
  bars = BARS
@@ -3,6 +3,7 @@ module Log
3
3
  BAR_MUTEX = Mutex.new
4
4
  BARS = []
5
5
  REMOVE = []
6
+ SILENCED = []
6
7
 
7
8
  def self.new_bar(max, options = {})
8
9
  cleanup_bars
@@ -24,6 +25,13 @@ module Log
24
25
  bar.depth = i
25
26
  end
26
27
  end
28
+ index = SILENCED.index bar
29
+ if index
30
+ SILENCED.delete_at index
31
+ SILENCED.each_with_index do |bar,i|
32
+ bar.depth = i
33
+ end
34
+ end
27
35
  end
28
36
  REMOVE.clear
29
37
  BARS.length
@@ -24,6 +24,12 @@ module Log
24
24
  (@ticks * 100) / @max
25
25
  end
26
26
 
27
+ def init
28
+ @start = @last_time = Time.now
29
+ @last_count = 0
30
+ report
31
+ end
32
+
27
33
  def tick(step = 1)
28
34
  return if ENV["RBBT_NO_PROGRESS"] == "true"
29
35
  @ticks += step
@@ -9,6 +9,7 @@ module Misc
9
9
  Persist::CONNECTIONS.values.each do |db|
10
10
  db.close if db.write?
11
11
  end
12
+ Log::ProgressBar::BARS.clear
12
13
  ObjectSpace.each_object(Mutex) do |m|
13
14
  begin
14
15
  m.unlock
@@ -297,7 +298,8 @@ module Misc
297
298
  end
298
299
 
299
300
 
300
- options = Misc.add_defaults options, :respawn => true, :cpus => cpus, :into => Set.new
301
+ #options = Misc.add_defaults options, :respawn => true, :cpus => cpus, :into => Set.new
302
+ options = Misc.add_defaults options, :respawn => true, :cpus => cpus
301
303
  options = Misc.add_defaults options, :bar => "Bootstrap in #{ options[:cpus] } cpus: #{ Misc.fingerprint Annotated.purge(elems) }"
302
304
  respawn = options[:respawn] and options[:cpus] and options[:cpus].to_i > 1
303
305
 
@@ -306,12 +308,13 @@ module Misc
306
308
  elem = elems[pos.to_i]
307
309
  elems.annotate elem if elems.respond_to? :annotate
308
310
  begin
309
- yield elem
311
+ res = yield elem
310
312
  rescue Interrupt
311
313
  Log.warn "Process #{Process.pid} was aborted"
312
314
  end
313
- raise RbbtProcessQueue::RbbtProcessQueueWorker::Respawn if respawn == :always and cpus > 1
314
- nil
315
+ res = nil unless options[:into]
316
+ raise RbbtProcessQueue::RbbtProcessQueueWorker::Respawn, res if respawn == :always and cpus > 1
317
+ res
315
318
  end
316
319
  end
317
320
 
@@ -279,6 +279,14 @@ class Step
279
279
  end
280
280
  end
281
281
 
282
+ def produce
283
+ return if done? and not dirty?
284
+ clean if dirty?
285
+ run(true) unless started?
286
+ join unless done?
287
+ self
288
+ end
289
+
282
290
  def fork(semaphore = nil)
283
291
  raise "Can not fork: Step is waiting for proces #{@pid} to finish" if not @pid.nil? and not Process.pid == @pid and Misc.pid_exists?(@pid) and not done? and info[:forked]
284
292
  @pid = Process.fork do
@@ -458,4 +458,12 @@ eum fugiat quo voluptas nulla pariatur?"
458
458
  ppp Misc.snake_case("KinaseSARfari")
459
459
  end
460
460
 
461
+ def test_bootstrap
462
+ Log.severity = 0
463
+ res = Misc.bootstrap((1..10).to_a, 2, :bar => "Test bootstrap ticks", :respawn => :always, :into => []) do |num|
464
+ sleep 1 + rand(2)
465
+ num
466
+ end
467
+ end
468
+
461
469
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.17.35
4
+ version: 5.17.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake