yeah  using subprocess popen seems fragile because if the ssh connection drops your done  you could run it in background and let the program print it is pid  later you can kill the program  that would be more robust to network failures 