Weird thread behavior in windows

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?

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs