spawner 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/spawner.rb +26 -12
- metadata +1 -1
data/History.txt
CHANGED
data/lib/spawner.rb
CHANGED
@@ -19,7 +19,7 @@ begin require 'fastthread'; rescue LoadError; end
|
|
19
19
|
#
|
20
20
|
class Spawner
|
21
21
|
|
22
|
-
VERSION = '1.0.
|
22
|
+
VERSION = '1.0.1'
|
23
23
|
|
24
24
|
@dev_null = test(?e, "/dev/null") ? "/dev/null" : "NUL:"
|
25
25
|
|
@@ -264,20 +264,27 @@ class Spawner
|
|
264
264
|
loop do
|
265
265
|
begin
|
266
266
|
io = IO.popen("#{@ruby} #{@tmp.path}", 'r')
|
267
|
-
cid = io.gets
|
267
|
+
cid = Integer(line = io.gets)
|
268
268
|
|
269
269
|
@cids.sync {@cids << cid} if cid > 0
|
270
270
|
Process.wait cid
|
271
|
-
rescue Exception =>
|
272
|
-
|
273
|
-
|
271
|
+
rescue Exception => err
|
272
|
+
child_err = Marshal.load(line) rescue nil
|
273
|
+
err = child_err unless child_err.nil?
|
274
|
+
|
275
|
+
STDERR.puts err.inspect
|
276
|
+
STDERR.puts err.backtrace.join("\n")
|
274
277
|
throw :die
|
275
278
|
ensure
|
279
|
+
line = io.read
|
280
|
+
child_err = Marshal.load(line) rescue nil
|
281
|
+
|
276
282
|
io.close rescue nil
|
277
283
|
@cids.sync {
|
278
284
|
@cids.delete cid
|
279
|
-
throw :die unless @cids.length < @spawn
|
285
|
+
throw :die unless @cids.length < @spawn or child_err
|
280
286
|
}
|
287
|
+
raise child_err unless child_err.nil?
|
281
288
|
end
|
282
289
|
|
283
290
|
throw :die if @stop
|
@@ -321,19 +328,26 @@ class Spawner
|
|
321
328
|
|
322
329
|
Dir.chdir cwd if cwd
|
323
330
|
env.each {|k,v| ENV[k.to_s] = v.to_s} if env
|
324
|
-
rescue Exception =>
|
325
|
-
|
326
|
-
|
331
|
+
rescue Exception => err
|
332
|
+
STDOUT.puts Marshal.dump(err)
|
333
|
+
STDOUT.flush
|
334
|
+
exit
|
327
335
|
end
|
328
336
|
|
329
|
-
STDOUT.
|
330
|
-
|
337
|
+
parent = STDOUT.dup
|
338
|
+
parent.puts Process.pid
|
339
|
+
parent.flush
|
331
340
|
|
332
341
|
STDIN.reopen stdin, 'r'
|
333
342
|
STDOUT.reopen stdout, 'a'
|
334
343
|
STDERR.reopen stderr, 'a'
|
335
344
|
|
336
|
-
|
345
|
+
begin
|
346
|
+
exec *argv
|
347
|
+
rescue Exception => err
|
348
|
+
parent.puts Marshal.dump(err)
|
349
|
+
parent.flush
|
350
|
+
end
|
337
351
|
PROG
|
338
352
|
|
339
353
|
tmp.close
|