in-parallel 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/in_parallel.gemspec +1 -1
- data/in_parallel/version.rb +1 -1
- data/lib/in_parallel.rb +27 -16
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71e83d885d72ee9199c9012d190f11c0e4fb7a23
|
4
|
+
data.tar.gz: 62274a9de6e81cd4772ce775904e49e9340b0346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a21762fb62f58b8a4b4eda90123bbefb41ed0dc078c07239b18a2ec2ba33b43ca5aadc10d99a8d7034ce31ffa662da081c8dbfc9a5030c45614160433c6a1a0e
|
7
|
+
data.tar.gz: dae9561fa380ebcfcbac4ea677fb44878b30d7248f389180578a089243fa3731e9ed815e666ae64bd4337edbf30fbd1e9475b6ffe52c26dd21ba4bf0922a709d
|
data/in_parallel.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
"processes if you try to spin up a LOT of processes. If you're looking for something simple and " +
|
22
22
|
"light-weight and on either linux or mac (forking processes is not supported on Windows), then this " +
|
23
23
|
"solution could be what you want."
|
24
|
-
spec.homepage = "https://github.com/
|
24
|
+
spec.homepage = "https://github.com/puppetlabs/in-parallel"
|
25
25
|
spec.license = "MIT"
|
26
26
|
|
27
27
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
data/in_parallel/version.rb
CHANGED
data/lib/in_parallel.rb
CHANGED
@@ -104,9 +104,11 @@ module InParallel
|
|
104
104
|
def self.wait_for_processes(proxy = self, binding = nil, timeout = nil, kill_all_on_error = false)
|
105
105
|
raise_error = nil
|
106
106
|
timeout ||= @@parallel_default_timeout
|
107
|
+
send_int = false
|
107
108
|
trap(:INT) do
|
108
109
|
# Can't use logger inside of trap
|
109
110
|
puts "Warning, recieved interrupt. Processing child results and exiting."
|
111
|
+
send_int = true
|
110
112
|
kill_child_processes
|
111
113
|
end
|
112
114
|
return unless Process.respond_to?(:fork)
|
@@ -170,18 +172,18 @@ module InParallel
|
|
170
172
|
@@background_objs.each { |obj| result_lookup(obj[:proxy], obj[:target], results_map) }
|
171
173
|
@@background_objs.clear
|
172
174
|
|
175
|
+
Process.kill("INT", Process.pid) if send_int
|
173
176
|
raise raise_error unless raise_error.nil?
|
174
|
-
|
175
177
|
return results
|
176
178
|
end
|
177
179
|
|
178
|
-
# private method to execute
|
180
|
+
# private method to execute a block of code in a separate process and store the STDOUT and return value for later retrieval
|
179
181
|
def self._execute_in_parallel(method_sym, obj = self, &block)
|
180
182
|
ret_val = nil
|
181
183
|
# Communicate the return value of the method or block
|
182
184
|
read_result, write_result = IO.pipe
|
185
|
+
Dir.mkdir('tmp') unless Dir.exists? 'tmp'
|
183
186
|
pid = fork do
|
184
|
-
Dir.mkdir('tmp') unless Dir.exists? 'tmp'
|
185
187
|
stdout_file = File.new("tmp/pp_#{Process.pid}", 'w')
|
186
188
|
exit_status = 0
|
187
189
|
trap(:INT) do
|
@@ -201,26 +203,17 @@ module InParallel
|
|
201
203
|
# close subprocess's copy of read_result since it only needs to write
|
202
204
|
read_result.close
|
203
205
|
ret_val = obj.instance_eval(&block)
|
204
|
-
|
205
|
-
# Have to serialize the value so it can be transmitted via IO
|
206
|
-
if (!ret_val.nil? && ret_val.singleton_methods && ret_val.class != TrueClass && ret_val.class != FalseClass && ret_val.class != Fixnum)
|
207
|
-
#in case there are other types that can't be duped
|
208
|
-
begin
|
209
|
-
ret_val = ret_val.dup
|
210
|
-
rescue StandardError => err
|
211
|
-
@@logger.warn "Warning: return value from child process #{ret_val} " +
|
212
|
-
"could not be transferred to parent process: #{err.message}"
|
213
|
-
end
|
214
|
-
end
|
206
|
+
ret_val = strip_singleton(ret_val)
|
215
207
|
# In case there are other types that can't be dumped
|
216
208
|
begin
|
209
|
+
# Write the result to the write_result IO stream.
|
217
210
|
Marshal.dump(ret_val, write_result) unless ret_val.nil?
|
218
211
|
rescue StandardError => err
|
219
212
|
@@logger.warn "Warning: return value from child process #{ret_val} " +
|
220
213
|
"could not be transferred to parent process: #{err.message}"
|
221
214
|
end
|
222
215
|
rescue Exception => err
|
223
|
-
@@logger.error "Error in process #{pid}: #{err.message}"
|
216
|
+
@@logger.error "Error in process #{Process.pid}: #{err.message}"
|
224
217
|
# Return the error if an error is rescued so we can re-throw in the main process.
|
225
218
|
Marshal.dump(err, write_result)
|
226
219
|
exit_status = 1
|
@@ -264,9 +257,27 @@ module InParallel
|
|
264
257
|
end
|
265
258
|
end
|
266
259
|
end
|
267
|
-
|
268
260
|
private_class_method :kill_child_processes
|
269
261
|
|
262
|
+
def self.strip_singleton(obj)
|
263
|
+
unless (obj.nil? || obj.singleton_methods.empty?)
|
264
|
+
obj = obj.dup
|
265
|
+
end
|
266
|
+
begin
|
267
|
+
obj.singleton_class.class_eval do
|
268
|
+
instance_variables.each { |v| instance_eval("remove_instance_variable(:#{v})") }
|
269
|
+
end
|
270
|
+
rescue TypeError # if no singleton_class exists for the object it raises a TypeError
|
271
|
+
end
|
272
|
+
|
273
|
+
# Recursively check any objects assigned to instance variables for singleton methods, or variables
|
274
|
+
obj.instance_variables.each do |v|
|
275
|
+
obj.instance_variable_set(v, strip_singleton(obj.instance_variable_get(v)))
|
276
|
+
end
|
277
|
+
obj
|
278
|
+
end
|
279
|
+
private_class_method :strip_singleton
|
280
|
+
|
270
281
|
# Private method to lookup results from the results_map and replace the
|
271
282
|
# temp values with actual return values
|
272
283
|
def self.result_lookup(proxy_obj, target_obj, results_map)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: in-parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- samwoods1
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- lib/in_parallel.rb
|
68
68
|
- lib/parallel_enumerable.rb
|
69
69
|
- lib/parallel_logger.rb
|
70
|
-
homepage: https://github.com/
|
70
|
+
homepage: https://github.com/puppetlabs/in-parallel
|
71
71
|
licenses:
|
72
72
|
- MIT
|
73
73
|
metadata: {}
|