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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/multiprocess-threads.rb +17 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3971fe9c71e887661b1dcefb3611b43d2b37ab1680cc723e2f57cdb47b294d3
4
- data.tar.gz: 9996f19aa9151b006f2affdfa811e9a337f5575dbc812fc16eadd353882bc4ab
3
+ metadata.gz: 6095dcdb64d939db503b5c14274f222dda55bfb7425f22d0b856687fba230261
4
+ data.tar.gz: edc5caed6ac842e850c9bb05a132f69ccaf0b46177faa1d1e0a36bc28f65fb63
5
5
  SHA512:
6
- metadata.gz: a78191430451155cacde7ea6aafb3cc2276903365aaaa327d217a484745582a76423504ec479e9759aa378946a924b9276fe19f0df5ce6eca0189f78c698783c
7
- data.tar.gz: 4026b9d12159c3a5c0cf24b4b3a32680e49e9e13d3addf4442c371d1a7209f30c9a9e902adb6abeb43a1ed34cfe54a7ce71c29cd2e4a2e0b00f1b3cbe8b4a1cd
6
+ metadata.gz: 8e82be7964807e0cfdf1e80a9a3966a10a60e03f8800c1b5bd76a6831fa21078ec16d9c90a5fc148db6e900de5aa5301e954654488eb7238c1f9b0b303fb0ee1
7
+ data.tar.gz: 52ff8ca8b4979c384fedd4d293c8313a7e81444788a6593d0ecfad2cd72d80ac2b9a4bf926104617d7ebfd78c4be6c7c5a4f92546ebb4aeda2084a7e3151d988
@@ -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).each(&:join)
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 res if res
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiprocess-threads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Yudin