# Is thread dead?

**URL:** <https://www.ruby-forum.com/t/is-thread-dead/108518>\
**Category:** Ruby\
**Created:** [July 4, 2007, 11:04am UTC](https://www.ruby-forum.com/t/is-thread-dead/108518 "2007-07-04T11:04:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirtyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@sirtyman](https://www.ruby-forum.com/u/sirtyman)\
**Post date:** [July 4, 2007, 11:04am UTC](https://www.ruby-forum.com/t/is-thread-dead/108518/1 "2007-07-04T11:04:48Z")

</div>

Hi guys,  
Here is piece of my code:

* * *

def executeAgent()

# establish telnet connection etc.

begin  
begin  
agent.cmd(‘String’ =\> “a\_command”) do |c|  
agentLogger.info(c.to\_str) #logs to output as well as to  
local file  
end  
rescue TimeoutError =\> e  
#exception handling + logging  
end  
rescue Errno::ECONNRESET, Errno::ECONNABORTED =\> e  
#exception handling + logging  
end

#logging that this function is going to finish because end prompt was  
met  
end #executeAgent

agentTr = Thread.new do  
begin  
executeAgent(myLogger)  
rescue Exception =\> e  
print("#{ **FILE** } #{ **LINE** }: executeAgent - #{e}\n")  
end  
end

## while true #something puts “agentTr alive” if agentTr.alive? #something end

agent.cmd(‘String’ =\> “a\_command”) - should never end, so logging to  
local file everything what a\_command throws should (in theory) never  
ends as well (if of course above exceptions wouldn’t occur - Timeout,  
ECONRESET etc.).  
But unfortunately looks like agentTr suddenly evaporates (agentTr.alive?  
returns false). Furthermore I’ve got none of logs from rescues blocks of  
code and moreover from the end of executeAgent function. Additionally  
I’ve got none of logs from Thread.new block.

Such situation appears after several hours (randomly)  
What is going on? Maybe something is not correct with exceptions  
handling or something like that.  
If a\_command finishes end prompt should be in my logs, if any timeout  
occur (in case a\_command is suspended) a log should be in logs as well  
etc.

I will be appreciated for any help.

Thanks in advance.  
MT
