开发者

Problem wuth Ruby threads

开发者 https://www.devze.com 2023-03-28 06:58 出处:网络
I write a simple bot using \"SimpleMUCClient\". But got error: app.rb:73:in stop\': deadlock detected (fatal)

I write a simple bot using "SimpleMUCClient". But got error: app.rb:73:in stop': deadlock detected (fatal) 开发者_Python百科from app.rb:73:in'. How to fix it?


Most likely the code you're running is executed in another thread. That particular thread is then joined (meaning Ruby waits for it to finish upon exiting the script) using Thread.join(). Calling Thread.stop() while also calling .join() is most likely the cause of the deadlock. Having said that you should following the guides of StackOverflow regarding how to ask questions properly, since you haven't done so I've down voted your question.

Joining a thread while still calling Thread.stop can be done as following:

th = Thread.new do
  Thread.stop
end

if th.status === 'sleep'
  th.run
else
  th.join
end

It's not the cleanest way but it works. Also, if you want to actually terminate a thread you'll have to call Thread.exit instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消