in-parallel 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/in_parallel/version.rb +1 -1
- data/lib/in_parallel.rb +5 -2
- data/lib/parallel_enumerable.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b4326e2eed1c0b8fb2a99ff7c353ea2b78ea05
|
4
|
+
data.tar.gz: 421617914e2609c3b8705cff7f49c50393d2d600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 707985cd17daa5dcf0de02b5135f1fc596d0b6009f0fc538fe42815d58565cdcf3c9a0db08a955d587a3986bab9c00de4ccff71cd0823c3fe7ee0cc5954bfc70
|
7
|
+
data.tar.gz: bfc404a413b43ce5c4780c2efa79b0fc056d0586db2e794357cf9dd04588032021be21f1e9bac3c330b3523bf43d01d907db0d30196bf8668bab60e3d28f075b
|
data/in_parallel/version.rb
CHANGED
data/lib/in_parallel.rb
CHANGED
@@ -40,6 +40,8 @@ module InParallel
|
|
40
40
|
# Private method to lookup results from the results_map and replace the
|
41
41
|
# temp values with actual return values
|
42
42
|
def self.result_lookup(proxy_obj, target_obj, results_map)
|
43
|
+
target_obj = eval('self', target_obj)
|
44
|
+
proxy_obj ||= target_obj
|
43
45
|
vars = (proxy_obj.instance_variables)
|
44
46
|
results = []
|
45
47
|
results_map.keys.each { |tmp_result|
|
@@ -76,7 +78,7 @@ module InParallel
|
|
76
78
|
Process.detach(@@process_infos.last[:pid])
|
77
79
|
@@process_infos.pop
|
78
80
|
else
|
79
|
-
@@background_objs << {:proxy => proxy, :target =>
|
81
|
+
@@background_objs << {:proxy => proxy, :target => block.binding}
|
80
82
|
return process_infos.last[:tmp_result]
|
81
83
|
end
|
82
84
|
return
|
@@ -154,11 +156,12 @@ module InParallel
|
|
154
156
|
# pass in the 'self' from the block.binding which is the instance of the class
|
155
157
|
# that contains the initial binding call.
|
156
158
|
# This gives us access to the local and instance variables from that context.
|
157
|
-
results = result_lookup(proxy,
|
159
|
+
results = result_lookup(proxy, binding, results_map) if binding
|
158
160
|
|
159
161
|
@@background_objs.each {|obj|
|
160
162
|
results = results.concat result_lookup(obj[:proxy], obj[:target], results_map)
|
161
163
|
}
|
164
|
+
@@background_objs.clear
|
162
165
|
|
163
166
|
return results
|
164
167
|
end
|
data/lib/parallel_enumerable.rb
CHANGED
@@ -13,11 +13,11 @@ module Enumerable
|
|
13
13
|
if Process.respond_to?(:fork) && count > 1
|
14
14
|
identifier ||= "#{caller_locations[0]}"
|
15
15
|
each do |item|
|
16
|
-
out = InParallel._execute_in_parallel(
|
17
|
-
puts "'each_in_parallel' forked process for '#{
|
16
|
+
out = InParallel::InParallelExecutor._execute_in_parallel(identifier) {block.call(item)}
|
17
|
+
puts "'each_in_parallel' forked process for '#{identifier}' - PID = '#{out[:pid]}'\n"
|
18
18
|
end
|
19
19
|
# return the array of values, no need to look up from the map.
|
20
|
-
return ::InParallelExecutor.wait_for_processes(nil, block.binding)
|
20
|
+
return InParallel::InParallelExecutor.wait_for_processes(nil, block.binding)
|
21
21
|
end
|
22
22
|
puts 'Warning: Fork is not supported on this OS, executing block normally' unless Process.respond_to? :fork
|
23
23
|
block.call
|