title: Running a nohup command through SSH with Python's Popen then logging out
body: <p>I'm trying to use this <a href="https://stackoverflow.com/a/19903649/5429658">answer</a> to issue a long-running process with nohup using <code>subprocess.Popen</code>, then exit the connection. </p>
  
  <p>From the login shell, if I run</p>
  
  <pre><code>$ nohup sleep 20 &amp;
  $ exit
  </code></pre>
  
  <p>I get the expected behavior, namely that I can log out while the sleep process is still running, and connect back later to check on its status. If I try to the same through Python, however, it seems as though the <code>exit</code> command does not get executed until the sleeping time is over.</p>
  
  <pre><code>import subprocess
  
  HOST=&lt;host&gt;
  sshProcess = subprocess.Popen(['ssh', HOST],
                                  stdin = subprocess.PIPE,
                                  stdout = subprocess.PIPE,
                                  universal_newlines = True,
                                  bufsize = 0)
  sshProcess.stdin.write("nohup sleep 20 &amp;\n")
  sshProcess.stdin.write("exit\n")
  sshProcess.stdin.close()
  </code></pre>
  
  <p>What am I missing?</p>