def killprocs(pattern):
 sh(('pkill -9 -f %s' % pattern))
 while True:
  try:
   pids = co(['pgrep', '-f', pattern])
  except CalledProcessError:
   pids = ''
  if pids:
   sh(('pkill -9 -f %s' % pattern))
   time.sleep(0.5)
  else:
   break

def killprocs ( pattern ) : sh ( ( 'pkill -9 -f %s' % pattern ) ) while True : try : pids = co ( [ 'pgrep' , '-f' , pattern ] ) except CalledProcessError : pids = '' if pids : sh ( ( 'pkill -9 -f %s' % pattern ) ) time . sleep ( 0.5 ) else : break
reliably terminate processes matching a pattern .