[英]Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter
我在測試Rails應用程序時在Ruby控制台中發現此錯誤。
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib /mongrel.rb:285:
in `run': Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter
所以我想我必須修補或重新安裝RubyCocoa。 但是我沒有任何內容可以做到這一點。 或者您可能有更好的方法來解決此問題?
這是我的環境:
正如Matthew在回答中指出的那樣,可能是導致此問題的插件。 他發現attachment_fu是原因之一。 (它可以使用Core Image進行圖像處理。)在此行中的config/initializers
(對於Rails應用程序)中創建文件將使警告靜音,但需要使用其他圖像處理器之一:
Technoweenie::AttachmentFu.default_processors.delete('CoreImage')
對我來說這不是問題。 我部署到非Mac服務器,並且由於這些服務器無法使用CoreImage,因此無論如何我都希望在開發過程中運行相同的東西。
如果查看/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/ objc/ruby_addition.rb
,則此文件位於文件的底部:
class Thread
class << self
alias :pre_rubycocoa_new :new
# Override Thread.new to prevent threads being created if there isn't
# runtime support for it
def new(*args,&block)
unless defined? @_rubycocoa_threads_allowed then
# If user has explicilty disabled thread support, also disable the
# check (for debugging/testing only)
@_rubycocoa_threads_allowed = ENV['RUBYCOCOA_THREAD_HOOK_DISABLE'] ||
OSX::RBRuntime.isRubyThreadingSupported?
end
if !@_rubycocoa_threads_allowed then
warn "#{caller[0]}: Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter"
end
pre_rubycocoa_new(*args,&block)
end
end
end
因此,對於初學者來說,我們會收到警告,但是無論如何它都會繼續調用原始Thread.new
。 我認為這個警告不是真正的問題。 在控制台中不斷看到它真是令人討厭。
如果您想跟蹤將猴子補丁引入Thread
,請使用grep查找可引入osx/cocoa
:
$ irb
>> Thread.new { puts 'hi' }
hi=> #<Thread:0x1011328e0 run>
>> require 'osx/cocoa'
=> true
>> Thread.new { puts 'hi' }
(irb):3:in `irb_binding': Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter
hi=> #<Thread:0x103bf76e8 run>
快速破解:
$ RUBYCOCOA_THREAD_HOOK_DISABLE=1 ./script/server --debugger
不同的快捷技巧:
$ echo "ENV['RUBYCOCOA_THREAD_HOOK_DISABLE']='1'" > config/initializers/disable_rubycocoa_warning.rb
引入它的可能不是雜種,而是Rails應用程序中的一些插件。 對我而言,attach_fu是元凶
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.