multiprocess-threads 0.0.3 → 0.0.5
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 +18 -1
- 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: ee69fe99caca1d5b798549717d5ed50ba94c7a25b3315e6e3cf63d9ea7475faa
|
4
|
+
data.tar.gz: 03c7bcb0a0b9f978f548e2e5674454de4aee460e2e12972975ee524b0925d40e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4a3f3da6b572a73a57f58dc01d7186678136d7d525ff51418c5e8c4a1c81f22913dd486d24b2b4f2a26779ef213cc9042790fd7fbe542190058dc567e5b09f
|
7
|
+
data.tar.gz: 06f8397df5186451cfd8b07cf14909e4539383f4f193ae27d33038e143161633e8d87ec4492a0e9f1880068451000680f05f49b3ecc221eb0b370baba9237554
|
data/lib/multiprocess-threads.rb
CHANGED
@@ -17,6 +17,8 @@ module MPThreads
|
|
17
17
|
return nil unless data
|
18
18
|
|
19
19
|
Marshal.load data # rubocop:disable Security/MarshalLoad
|
20
|
+
rescue Interrupt
|
21
|
+
nil
|
20
22
|
end
|
21
23
|
|
22
24
|
def write(data)
|
@@ -44,9 +46,14 @@ module MPThreads
|
|
44
46
|
proc_count, thr_count = Parallel.calc_resources count
|
45
47
|
proc_count.times do |i|
|
46
48
|
::Process.fork do
|
47
|
-
spawn_threads(thr_count, i, &block)
|
49
|
+
workers = spawn_threads(thr_count, i, &block)
|
50
|
+
workers.each(&:join)
|
51
|
+
rescue Interrupt
|
52
|
+
workers.each(&:exit)
|
48
53
|
end
|
49
54
|
end
|
55
|
+
rescue Interrupt
|
56
|
+
warn 'Exiting'
|
50
57
|
end
|
51
58
|
|
52
59
|
def spawn_threads(count, proc_i, &block)
|
@@ -68,3 +75,13 @@ module MPThreads
|
|
68
75
|
end
|
69
76
|
end
|
70
77
|
end
|
78
|
+
|
79
|
+
if $PROGRAM_NAME == __FILE__
|
80
|
+
mp = MPThreads::Parallel.new do |res|
|
81
|
+
puts res
|
82
|
+
end
|
83
|
+
|
84
|
+
mp.work do
|
85
|
+
rand(5)
|
86
|
+
end
|
87
|
+
end
|