Thread popen and broken pipe problem

Hello there, I try to execute a list of command in a thread thanks to
popen.
But during command execution user may wants to interrupt / kill the
execution process.
My code looks like that :

      @thread = Thread.new do
        @command_list.each {|name, cmd|
            IO.popen(cmd){ |@pipe|
              pipe.each_line {|l|
                  puts l
              }
            }
        }
      end

But when i try to @thread.kill I have a broken pipe error message on
the current command execution.

How to correctly finish and kill the thread without having such
errors?

thanks.

Found it,
when io is set after popen use, it's easy to get the process ID and
then to correctly kill it during its execution.

#get the process id

            IO.popen(cmd){ |pipe|
              current_process = pipe.id # Saving the PID
              pipe.each_line {|l|
                  puts l
              }

#kill the process

           Process.kill("KILL", current_process)

et voila.