rbbt-util 5.11.3 → 5.11.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: add772f9d207913045a9042098c44b2c5549215c
4
- data.tar.gz: 5932efc5c957bc4cf93de0228d4e654a47a788ce
3
+ metadata.gz: 1b14c182984b18f946f50ba4d5e07fafec05f8b5
4
+ data.tar.gz: f6cdb39396d9bd4871e74ab0eb63015373e415d9
5
5
  SHA512:
6
- metadata.gz: 864893d125d7ca6e03736829a5c77d11e936229dfd3569139c22b1acd10d8430156603b8a23f3ecf5c9b0602040278b6fff1482ccddde3cc9ca3686f40c16791
7
- data.tar.gz: 71da4b77c4fad1c83fcaa068118150bd6cfbc0e6e029a2bd3ffc2867293fa585cba4a4638eff98df9d4120fe2a95847c290ae7f6b07bfad2699ba15566f1a99c
6
+ metadata.gz: a51d7e12fb6fa32385092372830f5f3349fd697c0263f561c287cf17860b604c9544254444d0148c214381639f76e4de396b6d32c1d4a3cbf0e8bd631b45f3c2
7
+ data.tar.gz: d56ed3b1b3a048d5a68f1ad5b17f1548ed993387ff5fc7313b79716faeb31a96e5e7aa289b3a0d7821aeaa60ffbe2767ac771f9aba57c31b990b94186b1a77dc
data/lib/rbbt/persist.rb CHANGED
@@ -404,7 +404,7 @@ module Persist
404
404
 
405
405
  res = yield
406
406
 
407
- if persist_options[:no_load] == :stream
407
+ if persist_options[:no_load] == :stream
408
408
  case res
409
409
  when IO
410
410
  res = tee_stream(res, path, type, res.respond_to?(:callback)? res.callback : nil)
@@ -420,7 +420,6 @@ module Persist
420
420
  res = tee_stream(res.stream, path, type, res.respond_to?(:callback)? res.callback : nil)
421
421
  ConcurrentStream.setup res do
422
422
  begin
423
- iii [:unlock, lockfile.path]
424
423
  lockfile.unlock
425
424
  rescue
426
425
  Log.warn "Lockfile exception: " << $!.message
@@ -126,11 +126,8 @@ module TSV
126
126
  obj.abort if obj.respond_to? :abort
127
127
  raise $!
128
128
  ensure
129
- begin
130
- obj.close if obj.respond_to? :close and not obj.closed?
131
- ensure
132
- obj.join if obj.respond_to? :join
133
- end
129
+ obj.close if obj.respond_to? :close and not obj.closed?
130
+ obj.join if obj.respond_to? :join
134
131
  end
135
132
  when Path
136
133
  obj.open do |stream|
@@ -193,15 +190,24 @@ module TSV
193
190
  q.init &block
194
191
 
195
192
  pid = Process.fork do
193
+ #thread = Thread.new do
196
194
  Misc.purge_pipes(q.queue.swrite)
197
195
  traverse_obj(obj, options) do |*p|
198
196
  q.process *p
199
197
  end
200
198
  end
201
199
 
200
+ #thread.join
202
201
  Process.waitpid pid
202
+ raise "Traversal process ended with error status" unless $?.success?
203
203
  rescue Exception
204
- Log.error "Exception traversin in cpus: #{$!.message}"
204
+ Log.error "Exception traversing in cpus: #{$!.message}"
205
+ Log.exception $!
206
+
207
+ stream = obj_stream(obj)
208
+ stream.abort if stream.respond_to? :abort
209
+ stream = obj_stream(options[:into])
210
+ stream.abort if stream.respond_to? :abort
205
211
  q.abort
206
212
  raise $!
207
213
  ensure
@@ -60,15 +60,19 @@ class RbbtProcessQueue
60
60
  rescue Exception
61
61
  Log.error "Process monitor exception: #{$!.message}"
62
62
  @processes.each{|p| p.abort }
63
- @callback_thread.raise Aborted.new if @callback_thread
63
+ @callback_thread.raise $! if @callback_thread
64
64
  parent.raise $!
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
69
  def close_callback
70
- @callback_queue.push ClosedStream.new if @callback_thread.alive?
71
- @callback_thread.join
70
+ begin
71
+ @callback_queue.push ClosedStream.new if @callback_thread.alive?
72
+ rescue
73
+ Log.error "Error closing callback: #{$!.message}"
74
+ end
75
+ @callback_thread.join if @callback_thread.alive?
72
76
  end
73
77
 
74
78
  def join
@@ -20,6 +20,7 @@ class RbbtProcessQueue
20
20
  Signal.trap(:INT){ raise Aborted; }
21
21
  loop do
22
22
  p = @queue.pop
23
+ next if p.nil?
23
24
  raise p if Exception === p
24
25
  raise p.first if Exception === p.first
25
26
  res = @block.call *p
@@ -71,8 +71,11 @@ module ConcurrentStream
71
71
 
72
72
  def abort
73
73
  @threads.each{|t| t.raise Aborted.new } if @threads
74
+ @threads.each{|t| t.join } if @threads
74
75
  @pids.each{|pid| Process.kill :INT, pid } if @pids
76
+ @pids.each{|pid| Process.waitpid pid } if @pids
75
77
  @abort_callback.call if @abort_callback
78
+ @abort_callback = nil
76
79
  end
77
80
 
78
81
  def self.setup(stream, options = {}, &block)
@@ -253,8 +256,30 @@ module Misc
253
256
  alias tee_stream tee_stream_thread
254
257
  end
255
258
 
259
+ def self.read_full_stream(io)
260
+ str = ""
261
+ begin
262
+ while block = io.read(2048)
263
+ str << block
264
+ end
265
+ rescue
266
+ io.abort if io.respond_to? :abort
267
+ ensure
268
+ io.join if io.respond_to? :join
269
+ io.close if io.respond_to? :close
270
+ end
271
+ str
272
+ end
273
+
256
274
  def self.consume_stream(io)
257
- Thread.pass while block = io.read(2048)
275
+ begin
276
+ Thread.pass while block = io.read(2048)
277
+ rescue
278
+ io.abort if io.respond_to? :abort
279
+ ensure
280
+ io.join if io.respond_to? :join
281
+ io.close if io.respond_to? :close
282
+ end
258
283
  end
259
284
 
260
285
  def self.format_paragraph(text, size = 80, indent = 0, offset = 0)
@@ -332,9 +357,27 @@ module Misc
332
357
  end
333
358
 
334
359
  def self.read_stream(stream, size)
360
+ str = nil
361
+ Thread.pass while IO.select([stream],nil,nil,1).nil?
362
+ while not str = stream.read(size)
363
+ IO.select([stream],nil,nil,1)
364
+ Thread.pass
365
+ raise ClosedStream if stream.eof?
366
+ end
367
+
368
+ while str.length < size
369
+ raise ClosedStream if stream.eof?
370
+ IO.select([stream],nil,nil,1)
371
+ if new = stream.read(size-str.length)
372
+ str << new
373
+ end
374
+ end
375
+ str
376
+ end
377
+ def self._read_stream(stream, size)
335
378
  str = ""
336
379
  while (len=str.length) < size
337
- str << stream.read(size-len)
380
+ str << (stream.read(size-len) or break)
338
381
  end
339
382
  str
340
383
  end
@@ -1195,6 +1238,11 @@ end
1195
1238
  end
1196
1239
 
1197
1240
  def self.insist(times = 3, sleep = nil, msg = nil)
1241
+ if Array === times
1242
+ sleep_array = times
1243
+ times = sleep_array.length
1244
+ sleep = sleep_array.shift
1245
+ end
1198
1246
  try = 0
1199
1247
  begin
1200
1248
  yield
@@ -1206,6 +1254,7 @@ end
1206
1254
  end
1207
1255
  if sleep and try > 0
1208
1256
  sleep sleep
1257
+ sleep = sleep_array.shift if sleep_array
1209
1258
  else
1210
1259
  Thread.pass
1211
1260
  end
@@ -1332,47 +1381,28 @@ end
1332
1381
 
1333
1382
  hostname = Misc.hostname
1334
1383
  LOCK_MUTEX.synchronize do
1335
- Misc.insist 3, 0.1 do
1336
- begin
1337
- if File.exists? lock_path
1338
- info = Open.open(lock_path){|f| YAML.load(f) }
1339
- raise "No info" unless info
1340
-
1341
- if hostname == info["host"] and not Misc.pid_exists?(info["pid"])
1342
- Log.info("Removing lockfile: #{lock_path}. This pid #{Process.pid}. Content: #{info.inspect}")
1343
- FileUtils.rm lock_path
1384
+ Misc.insist 2, 0.1 do
1385
+ Misc.insist 3, 0.1 do
1386
+ begin
1387
+ if File.exists? lock_path
1388
+ info = Open.open(lock_path){|f| YAML.load(f) }
1389
+ raise "No info" unless info
1390
+
1391
+ if hostname == info["host"] and not Misc.pid_exists?(info["pid"])
1392
+ Log.info("Removing lockfile: #{lock_path}. This pid #{Process.pid}. Content: #{info.inspect}")
1393
+ FileUtils.rm lock_path
1394
+ end
1344
1395
  end
1396
+ rescue Exception
1397
+ FileUtils.rm lock_path if File.exists? lock_path
1398
+ lockfile = Lockfile.new(lock_path) unless File.exists? lock_path
1399
+ raise $!
1345
1400
  end
1346
- rescue Exception
1347
- FileUtils.rm lock_path if File.exists? lock_path
1348
- raise $!
1349
- ensure
1350
- lockfile = Lockfile.new(lock_path) unless File.exists? lock_path
1351
1401
  end
1352
1402
  end
1353
1403
  end
1354
1404
 
1355
- #begin
1356
- # Misc.insist 3 do
1357
- # LOCK_MUTEX.synchronize do
1358
- # if File.exists? lock_path and
1359
- # Misc.hostname == (info = Open.open(lock_path){|f| YAML.load(f) })["host"] and
1360
- # info["pid"] and not Misc.pid_exists?(info["pid"])
1361
-
1362
- # Log.info("Removing lockfile: #{lock_path}. This pid #{Process.pid}. Content: #{info.inspect}")
1363
- # FileUtils.rm lock_path
1364
- # end
1365
- # end
1366
- # end
1367
- #rescue
1368
- # Log.warn("Error checking lockfile #{lock_path}: #{$!.message}. Removing. Content: #{begin Open.read(lock_path) rescue "Could not open file" end}")
1369
- # FileUtils.rm lock_path if File.exists?(lock_path)
1370
- # lockfile = Lockfile.new(lock_path)
1371
- # retry
1372
- #end
1373
-
1374
1405
  begin
1375
-
1376
1406
  lockfile.lock
1377
1407
  res = yield lockfile
1378
1408
  rescue Lockfile::StolenLockError
@@ -1498,6 +1528,7 @@ end
1498
1528
  end
1499
1529
  FileUtils.mv tmp_path, path
1500
1530
  rescue Exception
1531
+ Log.error "Exception in sensiblewrite: #{$!.message} -- #{ Log.color :blue, path }"
1501
1532
  FileUtils.rm_f tmp_path if File.exists? tmp_path
1502
1533
  FileUtils.rm_f path if File.exists? path
1503
1534
  raise $!
@@ -167,7 +167,7 @@ class Step
167
167
  end
168
168
 
169
169
  def done?
170
- path and path.exists?
170
+ path and File.exists? path
171
171
  end
172
172
 
173
173
  def streaming?
@@ -40,135 +40,173 @@ class Step
40
40
  end
41
41
 
42
42
  class << self
43
- attr_accessor :log_relay_step
44
- end
43
+ attr_accessor :log_relay_step
44
+ end
45
45
 
46
- def relay_log(step)
47
- return self unless Task === self.task and not self.task.name.nil?
48
- if not self.respond_to? :original_log
49
- class << self
50
- attr_accessor :relay_step
51
- alias original_log log
52
- def log(status, message = nil)
53
- self.status = status
54
- message message
55
- relay_step.log([task.name.to_s, status.to_s] * ">", message.nil? ? nil : message ) unless relay_step.done? or relay_step.error? or relay_step.aborted?
56
- end
46
+ def relay_log(step)
47
+ return self unless Task === self.task and not self.task.name.nil?
48
+ if not self.respond_to? :original_log
49
+ class << self
50
+ attr_accessor :relay_step
51
+ alias original_log log
52
+ def log(status, message = nil)
53
+ self.status = status
54
+ message Log.uncolor message
55
+ relay_step.log([task.name.to_s, status.to_s] * ">", message.nil? ? nil : message ) unless (relay_step.done? or relay_step.error? or relay_step.aborted?)
57
56
  end
58
57
  end
59
- @relay_step = step
60
- self
61
58
  end
59
+ @relay_step = step
60
+ self
61
+ end
62
62
 
63
- def prepare_result(value, description = nil, info = {})
64
- #info = self.info
65
- case
66
- when IO === value
67
- begin
68
- case @task.result_type
69
- when :array
70
- array = []
71
- while line = value.gets
72
- array << line
73
- end
74
- array
75
- when :tsv
76
- TSV.open(value)
77
- else
78
- value.read
63
+ def prepare_result(value, description = nil, info = {})
64
+ #info = self.info
65
+ case
66
+ when IO === value
67
+ begin
68
+ case @task.result_type
69
+ when :array
70
+ array = []
71
+ while line = value.gets
72
+ array << line
79
73
  end
80
- rescue Exception
81
- value.abort if value.respond_to? :abort
82
- ensure
83
- value.join if value.respond_to? :join
84
- value.close unless value.closed?
85
- end
86
- when (not defined? Entity or description.nil? or not Entity.formats.include? description)
87
- value
88
- when (Annotated === value and info.empty?)
89
- value
90
- when Annotated === value
91
- annotations = value.annotations
92
- info.each do |k,v|
93
- value.send("#{h}=", v) if annotations.include? k
74
+ array
75
+ when :tsv
76
+ TSV.open(value)
77
+ else
78
+ value.read
94
79
  end
95
- value
96
- else
97
- Entity.formats[description].setup(value, info.merge(:format => description))
80
+ rescue Exception
81
+ value.abort if value.respond_to? :abort
82
+ ensure
83
+ value.join if value.respond_to? :join
84
+ value.close unless value.closed?
85
+ end
86
+ when (not defined? Entity or description.nil? or not Entity.formats.include? description)
87
+ value
88
+ when (Annotated === value and info.empty?)
89
+ value
90
+ when Annotated === value
91
+ annotations = value.annotations
92
+ info.each do |k,v|
93
+ value.send("#{h}=", v) if annotations.include? k
98
94
  end
95
+ value
96
+ else
97
+ Entity.formats[description].setup(value, info.merge(:format => description))
99
98
  end
99
+ end
100
100
 
101
- def get_stream
102
- @mutex.synchronize do
103
- begin
104
- IO === @result ? @result : nil
105
- ensure
106
- @result = nil
107
- end
101
+ def get_stream
102
+ @mutex.synchronize do
103
+ begin
104
+ IO === @result ? @result : nil
105
+ ensure
106
+ @result = nil
108
107
  end
109
108
  end
109
+ end
110
110
 
111
- def _exec
112
- @exec = true if @exec.nil?
113
- @task.exec_in((bindings ? bindings : self), *@inputs)
114
- end
111
+ def _exec
112
+ @exec = true if @exec.nil?
113
+ @task.exec_in((bindings ? bindings : self), *@inputs)
114
+ end
115
115
 
116
- def exec(no_load=false)
117
- dependencies.each{|dependency| dependency.exec(no_load) }
118
- @result = _exec
119
- @result = @result.stream if TSV::Dumper === @result
120
- no_load ? @result : prepare_result(@result, @task.result_description)
116
+ def exec(no_load=false)
117
+ dependencies.each{|dependency| dependency.exec(no_load) }
118
+ @result = _exec
119
+ @result = @result.stream if TSV::Dumper === @result
120
+ no_load ? @result : prepare_result(@result, @task.result_description)
121
+ end
122
+
123
+ def join
124
+ stream = get_stream if @result
125
+ begin
126
+ Misc.consume_stream stream if stream
127
+ rescue
128
+ stream.abort if stream.respond_to? :abort
129
+ raise $!
130
+ ensure
131
+ stream.join if stream.respond_to? :join and not stream.joined?
121
132
  end
122
133
 
123
- def join
124
- stream = get_stream
125
- begin
126
- Misc.consume_stream stream if stream
127
- rescue
128
- stream.abort if stream.respond_to? :abort
129
- raise $!
130
- ensure
131
- stream.join if stream.respond_to? :join and not stream.joined?
132
- end
134
+ return if not Open.exists? info_file
135
+ @pid ||= info[:pid]
133
136
 
137
+ #while not done?
138
+ # Misc.insist 2, 0.5 do
139
+ # raise "Job error while joining: #{info[:messages].last}" if error?
140
+ # raise "Job aborted while joining: #{info[:messages].last}" if aborted?
141
+ # raise "Job vanished while joining: #{@pid}" if @pid and not Misc.pid_exists? @pid
142
+ # end
143
+ #end
134
144
 
135
- if @pid.nil?
136
- dependencies.each{|dep| dep.join }
137
- self
138
- else
139
- begin
140
- Log.debug{"Waiting for pid: #{@pid}"}
141
- Process.waitpid @pid
142
- rescue Errno::ECHILD
143
- Log.debug{"Process #{ @pid } already finished: #{ path }"}
144
- end if Misc.pid_exists? @pid
145
- @pid = nil
146
- dependencies.each{|dep| dep.join }
147
- self
148
- end
145
+ Misc.insist [0.1, 0.2, 0.5, 1] do
146
+ @pid ||= info[:pid]
149
147
  end
150
148
 
151
- def checks
152
- rec_dependencies.collect{|dependency| dependency.path }.uniq
149
+ if @pid.nil?
150
+ dependencies.each{|dep| dep.join }
151
+ self
152
+ else
153
+ begin
154
+ Log.debug{"Waiting for pid: #{@pid}"}
155
+ Process.waitpid @pid
156
+ rescue Errno::ECHILD
157
+ Log.debug{"Process #{ @pid } already finished: #{ path }"}
158
+ end if Misc.pid_exists? @pid
159
+ @pid = nil
160
+ dependencies.each{|dep| dep.join }
161
+ self
153
162
  end
163
+ end
154
164
 
155
- def kill_children
156
- children_pids = info[:children_pids]
157
- if children_pids and children_pids.any?
158
- Log.medium("Killing children: #{ children_pids * ", " }")
159
- children_pids.each do |pid|
160
- Log.medium("Killing child #{ pid }")
161
- begin
162
- Process.kill "INT", pid
163
- rescue Exception
164
- Log.medium("Exception killing child #{ pid }: #{$!.message}")
165
- end
165
+ def checks
166
+ rec_dependencies.collect{|dependency| dependency.path }.uniq
167
+ end
168
+
169
+ def kill_children
170
+ children_pids = info[:children_pids]
171
+ if children_pids and children_pids.any?
172
+ Log.medium("Killing children: #{ children_pids * ", " }")
173
+ children_pids.each do |pid|
174
+ Log.medium("Killing child #{ pid }")
175
+ begin
176
+ Process.kill "INT", pid
177
+ rescue Exception
178
+ Log.medium("Exception killing child #{ pid }: #{$!.message}")
166
179
  end
167
180
  end
168
181
  end
182
+ end
169
183
 
170
- def run(no_load = false)
184
+ def run_dependencies(seen = [])
185
+ seen << self.path
186
+ dependencies.uniq.each{|dependency|
187
+ Log.info "#{Log.color :magenta, "Checking dependency"} #{Log.color :yellow, task.name.to_s || ""} => #{Log.color :yellow, dependency.task_name.to_s || ""}"
188
+ begin
189
+ next if seen.include? dependency.path
190
+ dependency.relay_log self
191
+ dependency.clean if not dependency.done? and dependency.error? or dependency.aborted?
192
+ dependency.clean if dependency.streaming? and not dependency.running?
193
+ dependency.run_dependencies(seen)
194
+ dependency.run true unless dependency.result or dependency.done?
195
+ seen << dependency.path
196
+ seen.concat dependency.rec_dependencies.collect{|d| d.path}
197
+ rescue Exception
198
+ backtrace = $!.backtrace
199
+ set_info :backtrace, backtrace
200
+ log(:error, "Exception processing dependency #{Log.color :yellow, dependency.task.name.to_s} -- #{$!.class}: #{$!.message}")
201
+ raise $!
202
+ end
203
+ }
204
+ end
171
205
 
206
+ def run(no_load = false)
207
+
208
+ result = nil
209
+ begin
172
210
  @mutex.synchronize do
173
211
  no_load = no_load ? :stream : false
174
212
  result = Persist.persist "Job", @task.result_type, :file => path, :check => checks, :no_load => no_load do |lockfile|
@@ -184,24 +222,8 @@ class Step
184
222
 
185
223
  log(:preparing, "Preparing job: #{Misc.fingerprint dependencies}")
186
224
  set_info :dependencies, dependencies.collect{|dep| [dep.task_name, dep.name]}
187
- seen_deps = []
188
- dependencies.uniq.each{|dependency|
189
- Log.info "#{Log.color :magenta, "Checking dependency"} #{Log.color :yellow, task.name.to_s || ""} => #{Log.color :yellow, dependency.task_name.to_s || ""}"
190
- begin
191
- next if seen_deps.include? dependency.path
192
- dependency.relay_log self
193
- dependency.clean if not dependency.done? and dependency.error?
194
- dependency.clean if dependency.streaming? and not dependency.running?
195
- dependency.run true unless dependency.result or dependency.done?
196
- seen_deps << dependency.path
197
- seen_deps.concat dependency.rec_dependencies.collect{|d| d.path}
198
- rescue Exception
199
- backtrace = $!.backtrace
200
- set_info :backtrace, backtrace
201
- log(:error, "Exception processing dependency #{Log.color :yellow, dependency.task.name.to_s} -- #{$!.class}: #{$!.message}")
202
- raise $!
203
- end
204
- }
225
+
226
+ run_dependencies
205
227
 
206
228
  set_info :inputs, Misc.remove_long_items(Misc.zip2hash(task.inputs, @inputs)) unless task.inputs.nil?
207
229
 
@@ -213,19 +235,6 @@ class Step
213
235
  rescue Aborted
214
236
  log(:error, "Aborted")
215
237
 
216
- # children_pids = info[:children_pids]
217
- # if children_pids and children_pids.any?
218
- # Log.medium("Killing children: #{ children_pids * ", " }")
219
- # children_pids.each do |pid|
220
- # Log.medium("Killing child #{ pid }")
221
- # begin
222
- # Process.kill "INT", pid
223
- # rescue Exception
224
- # Log.medium("Exception killing child #{ pid }: #{$!.message}")
225
- # end
226
- # end
227
- # end
228
-
229
238
  kill_children
230
239
  raise $!
231
240
  rescue Exception
@@ -240,8 +249,13 @@ class Step
240
249
  raise $!
241
250
  end
242
251
 
252
+ result = prepare_result result, @task.description, info if IO === result and ENV["RBBT_NO_STREAM"]
253
+ result = prepare_result result.stream, @task.description, info if TSV::Dumper === result and ENV["RBBT_NO_STREAM"]
254
+
243
255
  case result
244
256
  when IO
257
+ result = Misc.read_stream(result) if ENV["RBBT_NO_STREAM"]
258
+
245
259
  log :streaming, "#{Log.color :magenta, "Streaming task result IO"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}]"
246
260
  ConcurrentStream.setup result do
247
261
  begin
@@ -250,6 +264,8 @@ class Step
250
264
  log :done, "#{Log.color :red, "Completed task"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}] +#{time_elapsed.to_i} -- #{path}"
251
265
  rescue
252
266
  Log.exception $!
267
+ ensure
268
+ join
253
269
  end
254
270
  end
255
271
  result.abort_callback = Proc.new do
@@ -257,6 +273,8 @@ class Step
257
273
  log :error, "#{Log.color :red, "ERROR -- streamming aborted"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}] -- #{path}"
258
274
  rescue
259
275
  Log.exception $!
276
+ ensure
277
+ join
260
278
  end
261
279
  end
262
280
  when TSV::Dumper
@@ -269,6 +287,8 @@ class Step
269
287
  log :done, "#{Log.color :red, "Completed task"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}] +#{time_elapsed.to_i} -- #{path}"
270
288
  rescue
271
289
  Log.exception $!
290
+ ensure
291
+ join
272
292
  end
273
293
  end
274
294
  result.stream.abort_callback = Proc.new do
@@ -294,22 +314,21 @@ class Step
294
314
  @result = prepare_result result, @task.result_description
295
315
  end
296
316
  end
317
+ ensure
318
+ join unless no_load
319
+ end
297
320
  end
298
321
 
299
322
  def fork(semaphore = nil)
300
- raise "Can not fork: Step is waiting for proces #{@pid} to finish" if not @pid.nil?
323
+ raise "Can not fork: Step is waiting for proces #{@pid} to finish" if not @pid.nil? and not Process.pid == @pid
324
+ iii :forking
301
325
  @pid = Process.fork do
302
326
  begin
327
+ iii :forked
303
328
  RbbtSemaphore.wait_semaphore(semaphore) if semaphore
304
329
  FileUtils.mkdir_p File.dirname(path) unless Open.exists? File.dirname(path)
305
330
  begin
306
- res = run(true)
307
- io = get_stream
308
- if IO === io
309
- Misc.consume_stream(io)
310
- io.close unless io.closed?
311
- io.join if io.respond_to? :join and not io.joined?
312
- end
331
+ res = run
313
332
  rescue Aborted
314
333
  Log.debug{"Forked process aborted: #{path}"}
315
334
  log :aborted, "Aborted"
@@ -317,6 +336,8 @@ class Step
317
336
  rescue Exception
318
337
  Log.debug("Exception '#{$!.message}' caught on forked process: #{path}")
319
338
  raise $!
339
+ ensure
340
+ join
320
341
  end
321
342
 
322
343
  begin
@@ -351,7 +372,7 @@ class Step
351
372
  def abort
352
373
  @pid ||= info[:pid]
353
374
 
354
- return true unless info[:forked]
375
+ #return true unless info[:forked]
355
376
 
356
377
  case @pid
357
378
  when nil
@@ -368,10 +389,9 @@ class Step
368
389
  rescue Exception
369
390
  Log.debug("Aborted job #{@pid} was not killed: #{$!.message}")
370
391
  end
371
- log(:aborted, "Job aborted by user")
392
+ log(:aborted, "Job aborted")
372
393
  true
373
394
  end
374
- log(:aborted, "Job aborted by user")
375
395
  end
376
396
 
377
397
  def child(&block)
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.11.3
4
+ version: 5.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-06 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake