is the code catching typeerror just in case pid none  it would read better if you just said this up front  then some of this code could be cleaned up  if pid and self root helper child pid none while true try child pid utils find child pids pid except indexerror last process in the tree  return it return child pid