e-threadpool 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/threadpool/core.rb +10 -15
- data/lib/threadpool/worker.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
data/lib/threadpool/core.rb
CHANGED
@@ -17,7 +17,7 @@ module Ethreadpool
|
|
17
17
|
end
|
18
18
|
|
19
19
|
@workers = (0...@init_workers).map { Threadpool::Worker.new }
|
20
|
-
Thread.new {
|
20
|
+
@checker_thread = Thread.new { run_checker }
|
21
21
|
end
|
22
22
|
|
23
23
|
def load(job)
|
@@ -30,6 +30,8 @@ module Ethreadpool
|
|
30
30
|
loop do
|
31
31
|
worker = idle_worker
|
32
32
|
worker.nil? ? create_worker : break
|
33
|
+
|
34
|
+
# sleep here is a must, or MRI will get stucks
|
33
35
|
sleep(0.001)
|
34
36
|
end
|
35
37
|
|
@@ -38,26 +40,19 @@ module Ethreadpool
|
|
38
40
|
|
39
41
|
def shutdown
|
40
42
|
@teminate = true
|
41
|
-
|
42
|
-
loop do
|
43
|
-
return if busy_workers.count == 0
|
44
|
-
sleep(0.001)
|
45
|
-
end
|
43
|
+
@checker_thread.join
|
46
44
|
end
|
47
45
|
|
48
46
|
private
|
49
|
-
def
|
47
|
+
def run_checker
|
50
48
|
loop do
|
51
49
|
synchronize do
|
52
50
|
@workers.each do |w|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
puts "job is timeout."
|
59
|
-
w.cancel
|
60
|
-
end
|
51
|
+
w.process
|
52
|
+
t = w.start_time
|
53
|
+
if t && (Time.now - t > @timeout_secs)
|
54
|
+
puts "job #{w.jobid} is timeout."
|
55
|
+
w.cancel
|
61
56
|
end
|
62
57
|
|
63
58
|
end
|
data/lib/threadpool/worker.rb
CHANGED