Ruby 多后台线程 [英] Ruby multiple background threads
本文介绍了Ruby 多后台线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在超时的线程池中运行多个后台线程.该方案类似于:
I need to run multiple background threads in a thread pool with timeout. The scheme is something like:
#!/usr/bin/env ruby
require 'thread'
def foo(&block)
bar(block)
end
def bar(block)
Thread.abort_on_exception=true
@main = Thread.new { block.call }
end
foo {
sleep 1
puts 'test'
}
为什么我运行没有输出?(没有睡眠等待?)
Why if i run that i get no output? (and no sleep wait?)
推荐答案
试试 work_queue gem http://rubygems.org/gems/work_queue/
Try the work_queue gem http://rubygems.org/gems/work_queue/
这篇关于Ruby 多后台线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文