parallel_run 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -3
- data/lib/parallel_run.rb +25 -1
- data/parallel_run.gemspec +1 -2
- metadata +2 -18
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
parallel_run (0.
|
5
|
-
peach (>= 0.4)
|
4
|
+
parallel_run (0.3)
|
6
5
|
popen4 (>= 0.1.2)
|
7
6
|
|
8
7
|
GEM
|
@@ -10,7 +9,6 @@ GEM
|
|
10
9
|
specs:
|
11
10
|
Platform (0.4.0)
|
12
11
|
open4 (1.3.0)
|
13
|
-
peach (0.4)
|
14
12
|
popen4 (0.1.2)
|
15
13
|
Platform (>= 0.4.0)
|
16
14
|
open4 (>= 0.4.0)
|
data/lib/parallel_run.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'optparse'
|
2
|
-
require 'peach'
|
3
2
|
require 'popen4'
|
4
3
|
|
5
4
|
DEFAULT_TIME_FORMAT = "%H:%M:%S"
|
@@ -75,6 +74,31 @@ def replace s, value, k
|
|
75
74
|
s = s.gsub(/%k/, k.to_s)
|
76
75
|
s
|
77
76
|
end
|
77
|
+
module Enumerable
|
78
|
+
|
79
|
+
def _peach_run(pool = nil, &b)
|
80
|
+
pool ||= count
|
81
|
+
pool = 1 unless pool >= 1
|
82
|
+
div = (count.to_f/pool.to_f).ceil # should already be integer
|
83
|
+
div = 1 unless div >= 1 # each thread better do something!
|
84
|
+
|
85
|
+
threads = []
|
86
|
+
each_slice(div).with_index do |slice, idx|
|
87
|
+
threads << Thread.new(slice) do |thread_slice|
|
88
|
+
yield thread_slice, idx, div
|
89
|
+
end
|
90
|
+
end
|
91
|
+
threads.each{|t| t.join }
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def peach(pool = nil, &b)
|
96
|
+
_peach_run(pool) do |thread_slice, idx, div|
|
97
|
+
thread_slice.each{|elt| yield elt}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
78
102
|
|
79
103
|
result = {}
|
80
104
|
ARGV.each_with_index.to_a.peach($options[:workers]) do |f, index|
|
data/parallel_run.gemspec
CHANGED
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
|
6
6
|
s.name = "parallel_run"
|
7
|
-
s.version = "0.
|
7
|
+
s.version = "0.4"
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Bertrand Paquet"]
|
10
10
|
s.email = ["bertrand.paquet@gmail.com"]
|
@@ -21,5 +21,4 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.specification_version = 3
|
23
23
|
s.add_runtime_dependency(%q<popen4>, [">= 0.1.2"])
|
24
|
-
s.add_runtime_dependency(%q<peach>, [">= 0.4"])
|
25
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel_run
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: popen4
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.1.2
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: peach
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0.4'
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0.4'
|
46
30
|
description: Launch shell commands in parallel, capturing stdout and stderr
|
47
31
|
email:
|
48
32
|
- bertrand.paquet@gmail.com
|