Created
May 16, 2016 09:54
-
-
Save huacnlee/7e3abc70d45ab421340fd8138f576ad3 to your computer and use it in GitHub Desktop.
Ruby parallel run slow commands with Thread pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem 'thread' | |
require 'thread/pool' | |
pool = Thread.pool(20) | |
total = 10000 | |
total.times do |i| | |
pool.process do | |
stdout = "" | |
stdout << "\n" | |
stdout << "Queue #{i}/#{total}" | |
stdout << `./run-slow-command` + "\n" | |
stdout << "------------------------------------------------------------------\n" | |
puts stdout | |
end | |
end | |
pool.shutdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment