spawner 1.0.0 → 1.0.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.
Files changed (3) hide show
  1. data/History.txt +6 -0
  2. data/lib/spawner.rb +26 -12
  3. metadata +1 -1
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.0.1 / 2008-09-15
2
+
3
+ * 1 minor enhancement
4
+ * Now returns errors back up to the spawner if the child cannot exec
5
+ the desired process
6
+
1
7
  == 1.0.0 / 2008-09-14
2
8
 
3
9
  * 1 major enhancement
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.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.to_i
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 => e
272
- STDERR.puts e.inspect
273
- STDERR.puts e.backtrace.join("\n")
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 => e
325
- STDERR.warn e
326
- abort
331
+ rescue Exception => err
332
+ STDOUT.puts Marshal.dump(err)
333
+ STDOUT.flush
334
+ exit
327
335
  end
328
336
 
329
- STDOUT.puts Process.pid
330
- STDOUT.flush
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
- exec *argv
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spawner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease