title: How to execute a non-blocking script in python and get its return code?
body: <p>I am trying to execute a non-blocking bash script from python and to get its return code. Here is my function so far:</p>
  
  <pre><code>def run_bash_script(script_fullname, logfile):
      my_cmd = ". " + script_fullname + " &gt;" + logfile +" 2&gt;&amp;1"
      p = subprocess.Popen(my_cmd, shell=True)
      os.waitpid(p.pid, 0)
      print(p.returncode)
  </code></pre>
  
  <p>As you can see, all the output is redirected into a log file, which I can monitor while the bash process is running. </p>
  
  <p>However, the last command just returns 'None' instead of a useful exit code. </p>
  
  <p>What am I doing wrong here?</p>