Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created May 16, 2016 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huacnlee/7e3abc70d45ab421340fd8138f576ad3 to your computer and use it in GitHub Desktop.
Save huacnlee/7e3abc70d45ab421340fd8138f576ad3 to your computer and use it in GitHub Desktop.
Ruby parallel run slow commands with Thread pool
# 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