multiprocess-threads 0.0.2 → 0.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.
- checksums.yaml +4 -4
- data/lib/multiprocess-threads.rb +17 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6095dcdb64d939db503b5c14274f222dda55bfb7425f22d0b856687fba230261
|
4
|
+
data.tar.gz: edc5caed6ac842e850c9bb05a132f69ccaf0b46177faa1d1e0a36bc28f65fb63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e82be7964807e0cfdf1e80a9a3966a10a60e03f8800c1b5bd76a6831fa21078ec16d9c90a5fc148db6e900de5aa5301e954654488eb7238c1f9b0b303fb0ee1
|
7
|
+
data.tar.gz: 52ff8ca8b4979c384fedd4d293c8313a7e81444788a6593d0ecfad2cd72d80ac2b9a4bf926104617d7ebfd78c4be6c7c5a4f92546ebb4aeda2084a7e3151d988
|
data/lib/multiprocess-threads.rb
CHANGED
@@ -44,16 +44,21 @@ module MPThreads
|
|
44
44
|
proc_count, thr_count = Parallel.calc_resources count
|
45
45
|
proc_count.times do |i|
|
46
46
|
::Process.fork do
|
47
|
-
spawn_threads(thr_count, i, &block)
|
47
|
+
workers = spawn_threads(thr_count, i, &block)
|
48
|
+
workers.each(&:join)
|
49
|
+
rescue Interrupt
|
50
|
+
workers.each(&:exit)
|
48
51
|
end
|
49
52
|
end
|
53
|
+
rescue Interrupt
|
54
|
+
warn 'Exiting'
|
50
55
|
end
|
51
56
|
|
52
57
|
def spawn_threads(count, proc_i, &block)
|
53
58
|
count.times.map do |i|
|
54
59
|
Thread.new do
|
55
60
|
res = @channel.instance_exec(proc_i, i, &block)
|
56
|
-
@channel.write
|
61
|
+
@channel.write(res) if res
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
@@ -68,3 +73,13 @@ module MPThreads
|
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
76
|
+
|
77
|
+
if $PROGRAM_NAME == __FILE__
|
78
|
+
mp = MPThreads::Parallel.new do |res|
|
79
|
+
puts res
|
80
|
+
end
|
81
|
+
|
82
|
+
mp.work do
|
83
|
+
rand(5)
|
84
|
+
end
|
85
|
+
end
|