title: Why does manage.py execution script run twice when using it under if __name__ == "__main__"
body: <p>Goal. 
  When launching django framework also launch other PY scripts that rely on django objects.
  Get the server and port number from a config file.</p>
  
  <p>Problem: 
  The Popen seems to run twice and I'm not sure why?</p>
  
  <pre><code>#!/usr/bin/env python
  import os
  import sys
  import subprocess
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.localsettings")
  from django.core.management import execute_from_command_line
  
  def getargs(): 
      try:
          f = open("config")
          data = []
          for line in f:
              data.append(line)
          f.close()
          server = data[0].rstrip()
          port = data[1]
          newargs = ['lmanage.py', 'runserver', server + ':' + port]
          return newargs
  
      except Exception as e:
          print e
          pass
  
  if __name__ == "__main__":
  
      #Launching Checker
      try: 
          checker = subprocess.Popen([sys.executable, os.path.join(os.getcwd() + "checker.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
          print checker.pid
      except Exception as e:
          print e
          pass 
      print "end"
  
      execute_from_command_line(getargs())
  </code></pre>
  
  <p>Outputs: </p>
  
  <pre><code>16200
  end
  29716
  end
  Validating models...
  </code></pre>
  
  <p>This is my first attempt so if anyone knows of a better way to do this then feel free to let me know.   </p>
  
  <p>Thanks everyone. </p>