# Weird thread behavior in windows

**URL:** <https://www.ruby-forum.com/t/weird-thread-behavior-in-windows/131912>\
**Category:** Ruby\
**Created:** [March 14, 2008, 10:17am UTC](https://www.ruby-forum.com/t/weird-thread-behavior-in-windows/131912 "2008-03-14T10:17:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [March 14, 2008, 10:17am UTC](https://www.ruby-forum.com/t/weird-thread-behavior-in-windows/131912/1 "2008-03-14T10:17:15Z")

</div>

Hello All.

I have some code that looks like this.

@tasks.run do |cmd|  
@logger.info “Threading #{cmd} with timeout of  
#{@entries[cmd]}”  
Thread.new(cmd) { |cmd|  
Timeout::timeout(@entries[cmd]) do  
begin  
# Something that should be interrupted if it  
takes too much time…  
@logger.info( cmd + " Finished : " +  
eval(cmd).to\_s)  
rescue Timeout::Error  
@logger.error( cmd + " Timed out : " )  
rescue Exception =\> detail  
@logger.error(“Error during Processing #{cmd}  
\n” + detail.message + detail.backtrace.join("\n") )  
ensure  
Thread.exit  
end  
end  
}  
end

Some of the tasks are calls to the backtick operator for shell  
functions.

If a backtick operation times out the thread is not killed. I can  
watch the process list and see that the process is running, the logger  
tells me when it started and when it should be forcefully terminated  
but the thread just stays there. Once the task is finished it prints  
the “timed out” message so obviously the exception was raised but it  
did not kill the eval and turn the control over to the script. Also  
once the timeout has exceeded no new tasks are being threaded. It’s  
like the whole script is waiting for this one task to get done before  
it can go any further.

Any ideas on how I can correct this code so that the running process  
can get killed?

---

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [March 14, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/weird-thread-behavior-in-windows/131912/2 "2008-03-14T17:03:32Z")

</div>

Maybe use system or popen for the processes?

> Any ideas on how I can correct this code so that the running process  
> can get killed?
