Skip to content
Browse files

Tested hung process detection on Windows and Nix with a version of FF…

…MPEG that hangs every time.
  • Loading branch information...
1 parent 3c5095e commit 739688bf9a964e5bf15d7e77324ca191d3599940 Stephen von Takach committed Jun 7, 2012
Showing with 14 additions and 5 deletions.
  1. +9 −3 lib/ffmpeg/io_monkey.rb
  2. +5 −2 lib/ffmpeg/transcoder.rb
View
12 lib/ffmpeg/io_monkey.rb
@@ -21,12 +21,12 @@
# Monkey Patch timeout support into the IO class
#
class IO
- def each_with_timeout(timeout, sep_string=$/)
+ def each_with_timeout(pid, timeout, sep_string=$/)
q = Queue.new
th = nil
timer_set = lambda do |timeout|
- th = new_thread{ to(timeout){ q.pop } }
+ th = new_thread(pid){ to(timeout){ q.pop } }
end
timer_cancel = lambda do |timeout|
@@ -49,13 +49,19 @@ def each_with_timeout(timeout, sep_string=$/)
private
- def new_thread(*a, &b)
+ def new_thread(pid, *a, &b)
cur = Thread.current
Thread.new(*a) do |*a|
begin
b[*a]
rescue Exception => e
cur.raise e
+ if RUBY_PLATFORM =~ /(win|w)(32|64)$/
+ require 'win32/process'
+ Process.kill(1, pid)
+ else
+ Process.kill('INT', pid)
+ end
end
end
end
View
7 lib/ffmpeg/transcoder.rb
@@ -1,6 +1,10 @@
require 'open3'
require 'shellwords'
+if RUBY_PLATFORM =~ /(win|w)(32|64)$/
+ require 'win32/process'
+end
+
module FFMPEG
class Transcoder
@@timeout = 200
@@ -63,13 +67,12 @@ def run
end
if @@timeout != false
- stderr.each_with_timeout(@@timeout, "r", &next_line)
+ stderr.each_with_timeout(pid, @@timeout, "r", &next_line)
else
stderr.each("r", &next_line)
end
rescue Timeout::Error => e
- Process.kill('SIGKILL', pid)
FFMPEG.logger.error "Process hung...\nCommand\n#{command}\nOutput\n#{output}\n"
raise "Process hung"
end

0 comments on commit 739688b

Please sign in to comment.
Something went wrong with that request. Please try again.