process_starter 1.0.3 → 1.0.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.
- data/lib/process_starter.rb +6 -5
- data/test/test_process_starter.rb +1 -1
- metadata +3 -3
data/lib/process_starter.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'fcntl'
|
5
5
|
|
6
|
-
#
|
6
|
+
# gem for spawn processes in ruby 1.8 avoiding fork/exec,
|
7
|
+
# see https://github.com/rtomayko/posix-spawn
|
7
8
|
begin; require( 'posix/spawn' ) ; rescue LoadError ; end
|
8
9
|
|
9
10
|
module ProcessStarter
|
@@ -20,11 +21,11 @@ module ProcessStarter
|
|
20
21
|
# not waiting for it's finish, so child process run in parralel
|
21
22
|
# not inheritting file descriptors, so it finds and closes all opened handels
|
22
23
|
# works in windows and linux
|
23
|
-
def self.start(s)
|
24
|
+
def self.start(s, allowed_methods=[:psexec,:start,:posix_spawn,:spawn,:fork])
|
24
25
|
log "********* ProcessStarter.start INVOKING EXTERNAL COMMAND #{s}, WINRUN IS #{WINRUN}, HAVE_POSIX_SPAWN IS #{HAVE_POSIX_SPAWN}, HAVE_SPAWN is #{HAVE_SPAWN}"
|
25
26
|
if WINRUN
|
26
27
|
@@have_psexec ||= ((`psexec /?` rescue "") =~ /computer/ ? 2 : 1)
|
27
|
-
if @@have_psexec == 2
|
28
|
+
if @@have_psexec == 2 and allowed_methods.include?(:psexec)
|
28
29
|
log "starting using psexec"
|
29
30
|
r = system("psexec -d #{s}")
|
30
31
|
else
|
@@ -33,11 +34,11 @@ module ProcessStarter
|
|
33
34
|
end
|
34
35
|
else
|
35
36
|
log "Executing in Linux style"
|
36
|
-
if HAVE_POSIX_SPAWN
|
37
|
+
if HAVE_POSIX_SPAWN and allowed_methods.include?(:posix_spawn)
|
37
38
|
close_them = Hash[ close_io().map {|x| [x, :close]} ]
|
38
39
|
log "POSIX::Spawn::spawn with close descriptors: #{close_them.inspect}"
|
39
40
|
Process.detach POSIX::Spawn::spawn( s, close_them)
|
40
|
-
elsif HAVE_SPAWN
|
41
|
+
elsif HAVE_SPAWN and allowed_methods.include?(:spawn)
|
41
42
|
# we hope on http://www.ruby-doc.org/core-1.9.3/Process.html#method-c-spawn
|
42
43
|
# [close_others => true] option
|
43
44
|
# TODO: check it
|
@@ -31,7 +31,7 @@ class ProcessStarterTest < Test::Unit::TestCase
|
|
31
31
|
|
32
32
|
# r = ProcessStarter.start("ruby test/test2child.arb 120 >test/chout 2>&1")
|
33
33
|
|
34
|
-
ProcessStarter.start("ruby test/test2child.arb 120")
|
34
|
+
ProcessStarter.start("ruby test/test2child.arb 120", [:start,:fork] )
|
35
35
|
#stat = Process::waitpid(r)
|
36
36
|
|
37
37
|
#puts "i started child, r=#{r}, status = #{stat.inspect}"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_starter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavel Vasev
|