title: using argparse to start flask server
body: <p>I have created a flask application and want to run the server(<code>$ python run.py</code> ) but before that want to do some basic db tasks on running <code>$ python run.py --init</code></p>
  
  <p><strong>Code</strong> (run.py):</p>
  
  <pre><code>def init():
      do_dbstuff()
      start_server()
  
  def do_dbstuff():
      # doing db stuff
  
  def start_server():
      app.run(host='127.0.0.1', port=8080, debug=True)
  
  parser = argparse.ArgumentParser(description="Welcome to my server", prog="Simpleserver")
  
  parser.add_argument('--init', dest='run_init', action='store_true', help="does db stuff and starts the server")
  parser.add_argument('--dbstuff', dest='run_do_dbstuff', action='store_true', help="does db stuff")
  
  args = parser.parse_args()
  
  if args.run_init:
      init()
  elif args.run_do_db_stuff:
      do_dbstuff()
  else:
      start_server()
  </code></pre>
  
  <p>Above code works, but the problem is when the server gets started <code>init()</code> function is called again( want it to run only once).</p>
  
  <p>Why is that happening?</p>
  
  <p>Thanks</p>