Skip to content

Commit

Permalink
Use :pgroup option when starting subprocesses
Browse files Browse the repository at this point in the history
This makes it easier and faster to kill spawned git processes.
Repetitive `pgrep` command for collecting PIDs is no longer required.
Unfortunately, :pgroup option is not supported on Ruby 1.8 so we can't
remove the old implementation of `killall`.
  • Loading branch information
junegunn committed Feb 17, 2015
1 parent 4a96db8 commit 308fb9b
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1003,23 +1003,36 @@ function! s:update_ruby()
%["#{arg.gsub('"', '\"')}"]
end

def killall pid
pids = [pid]
unless `which pgrep 2> /dev/null`.empty?
children = pids
until children.empty?
children = children.map { |pid|
`pgrep -P #{pid}`.lines.map { |l| l.chomp }
}.flatten
pids += children
end
end
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
end

require 'rubygems'
require 'thread'
require 'fileutils'
require 'timeout'

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9')
def popen cmd
IO.popen(cmd, :pgroup => true)
end
def killall pid
Process.kill 'TERM', - pid rescue nil
end
else
def popen cmd
IO.popen(cmd)
end
def killall pid
pids = [pid]
unless `which pgrep 2> /dev/null`.empty?
children = pids
until children.empty?
children = children.map { |pid|
`pgrep -P #{pid}`.lines.map { |l| l.chomp }
}.flatten
pids += children
end
end
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
end
end
running = true
iswin = VIM::evaluate('s:is_win').to_i == 1
pull = VIM::evaluate('s:update.pull').to_i == 1
Expand Down Expand Up @@ -1086,7 +1099,7 @@ function! s:update_ruby()
File.unlink tmp rescue nil
end
else
fd = IO.popen(cmd).extend(PlugStream)
fd = popen(cmd).extend(PlugStream)
first_line = true
log_prob = 1.0 / nthr
while line = Timeout::timeout(timeout) { fd.get_line }
Expand Down

0 comments on commit 308fb9b

Please sign in to comment.