Ruby 在线程内运行Sinatra应用程序不会';行不通
我尝试在新线程中运行Sinatra应用程序,以便在脚本中运行其他内容,但当我这样做时:Ruby 在线程内运行Sinatra应用程序不会';行不通,ruby,sinatra,Ruby,Sinatra,我尝试在新线程中运行Sinatra应用程序,以便在脚本中运行其他内容,但当我这样做时: require 'sinatra/base' class App < Sinatra::Base ...some routes... end Thread.new do App.run! end 需要'sinatra/base' 类应用程序
require 'sinatra/base'
class App < Sinatra::Base
...some routes...
end
Thread.new do
App.run!
end
需要'sinatra/base'
类应用程序
没有发生任何事情,Sinatra服务器未启动。为了实现这一点,我还缺少什么吗?最后,我在一个线程中运行了另一个ruby进程,但来自Sinatra应用程序,它运行得很好
class App < Sinatra::Base
threads = []
threads <<
Thread.new do
Some::Other::Thing
rescue StandardError => e
$stderr << e.message
$stderr << e.backtrace.join("\n")
end
trap('INT') do
puts 'trapping'
threads.each do |t|
puts 'killing'
Thread.kill t
end
end
run!
end
class-App