Thread Status
Each thread has a status that may be one of the following:
| When the thread is executing |
| When the thread is sleeping or waiting on I/O |
| When the thread is aborting |
| When the thread terminated normally |
| When the thread terminated with an exception |
You can obtain the status of a thread using the status
method. The status is also shown when you inspect a thread, in which case either a nil
or a false
status is shown as dead
.
thread_status.rb
puts( Thread.main.inspect ) #=> #<Thread:0x28955c8 run> puts( Thread.new{ sleep }.kill.inspect ) #=> #<Thread:0x28cddc0 dead> puts( Thread.new{ sleep }.inspect ) #=> #<Thread:0x28cdd48 sleep> thread1 = Thread.new{ } puts( thread1.status ) #=> false thread2 = Thread.new{ raise( "Exception ...
Get The Book of Ruby now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.