picky 3.1.7 → 3.1.8
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.
- data/lib/picky/cores.rb +23 -33
- metadata +3 -3
data/lib/picky/cores.rb
CHANGED
@@ -16,59 +16,49 @@ module Picky
|
|
16
16
|
# Options include:
|
17
17
|
# * max: Maximum # of processors to use. Default is all it can get.
|
18
18
|
#
|
19
|
-
def self.forked
|
20
|
-
return if
|
19
|
+
def self.forked elements, options = {}, &block
|
20
|
+
return if elements.empty?
|
21
21
|
raise "Block argument needed when running Cores.forked" unless block_given?
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# Don't fork if there's just one element.
|
23
|
+
# Note: Not using a generator because Enumerator#each
|
24
|
+
# is exhibiting problems in some Rubies on some OSs
|
25
|
+
# (see e.g. http://redmine.ruby-lang.org/issues/5003).
|
27
26
|
#
|
28
|
-
|
29
|
-
|
30
|
-
yield element # THINK yield generator.next results in trouble. Why?
|
31
|
-
end
|
32
|
-
return
|
33
|
-
end
|
27
|
+
elements = elements.dup
|
28
|
+
elements = elements.sort_by { rand } if options[:randomly]
|
34
29
|
|
35
30
|
# Get the maximum number of processors.
|
36
31
|
#
|
37
|
-
max
|
38
|
-
|
32
|
+
max = max_processors options
|
33
|
+
processing = 0
|
39
34
|
|
40
|
-
#
|
41
|
-
#
|
42
35
|
loop do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
currently_processing = currently_processing + 1
|
48
|
-
|
49
|
-
element = nil
|
50
|
-
begin
|
51
|
-
element = generator.next
|
52
|
-
rescue StopIteration => si
|
53
|
-
break
|
54
|
-
end
|
36
|
+
while processing < max
|
37
|
+
# Get the next element
|
38
|
+
#
|
39
|
+
element = elements.shift
|
55
40
|
break unless element
|
41
|
+
processing += 1
|
56
42
|
|
43
|
+
# Fork and yield.
|
44
|
+
#
|
57
45
|
Process.fork do
|
58
|
-
sleep 0.
|
59
|
-
|
46
|
+
sleep 0.05*processing
|
47
|
+
block.call element
|
60
48
|
end
|
61
|
-
|
62
49
|
end
|
63
50
|
|
51
|
+
# Block and wait for any child to finish.
|
52
|
+
#
|
64
53
|
begin
|
65
|
-
Process.wait 0
|
54
|
+
Process.wait 0
|
66
55
|
rescue Errno::ECHILD => e
|
67
56
|
break
|
68
57
|
ensure
|
69
|
-
|
58
|
+
processing -= 1
|
70
59
|
end
|
71
60
|
end
|
61
|
+
|
72
62
|
end
|
73
63
|
|
74
64
|
# Return the number of maximum usable processors.
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.1.
|
5
|
+
version: 3.1.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-10-12 00:00:00 +02:00
|
14
14
|
default_executable: picky
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 3.1.
|
35
|
+
version: 3.1.8
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id002
|
38
38
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|