rails中缺少`threadsafe!`方法

时间:2014-07-02 11:48:11

标签: ruby multithreading ruby-on-rails-4

要在rails中启用多线程,我在config.threadsafe!中设置了development.rb

我收到错误说:

'method_missing': undefined method `threadsafe!' (NoMethodError)

我正在使用rails 4.1.1和ruby 2.0.0。请任何人帮助我解决这个问题的原因和方法。

development.rb

Rails.application.configure do
  config.cache_classes = false
  config.threadsafe! 
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.raise_runtime_errors = true
end

错误:

/home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined
 method `threadsafe!' for #<Rails::Application::Configuration:0x0000000482a6c8> (NoMethodError)
    from /home/gayithri/workspace/ThreadDemo/config/environments/development.rb:8:in `block in <top (required)>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/railtie.rb:210:in `instance_eval'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/railtie.rb:210:in `configure'
    from /home/gayithri/workspace/ThreadDemo/config/environments/development.rb:1:in `<top (required)>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/engine.rb:594:in `block (2 levels) in <class:Engine>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/engine.rb:593:in `each'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/engine.rb:593:in `block in <class:Engine>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:44:in `each'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `call'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /home/gayithri/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
    from /home/gayithri/workspace/ThreadDemo/config/environment.rb:5:in `<top (required)>'
    from /home/gayithri/workspace/ThreadDemo/config.ru:3:in `require'
    from /home/gayithri/workspace/ThreadDemo/config.ru:3:in `block in <main>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /home/gayithri/workspace/ThreadDemo/config.ru:in `new'
    from /home/gayithri/workspace/ThreadDemo/config.ru:in `<main>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:50:in `app'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:67:in `start'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/gayithri/workspace/ThreadDemo/bin/rails:8:in `require'
    from /home/gayithri/workspace/ThreadDemo/bin/rails:8:in `<top (required)>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
    from /home/gayithri/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /home/gayithri/workspace/ThreadDemo/bin/spring:16:in `require'
    from /home/gayithri/workspace/ThreadDemo/bin/spring:16:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

1 个答案:

答案 0 :(得分:9)

config.threadsafe!已不再需要,已被删除。 Rails默认是线程安全的。它在此配置选项上所做的一切对于多进程单线程部署也是有效的,所以现在它只是执行此操作。

Removing config.threadsafe!