title: How to run gunicorn inside python not as a command line?
body: <p>I have a flask application.</p>
  <p>I run it in production with this command:</p>
  <pre><code>python -m gunicorn -w 1 -b 0.0.0.0:5000 &quot;path.to.wsgi:return_app()&quot;
  </code></pre>
  <p>Instead, I want to run it inside a my_file.py</p>
  <p>I need a function to run and it should accept the app object and port binding and number of workers</p>
  <p>How can I do that?</p>
  <p>I need something like this <strong>psudo code</strong>:</p>
  <pre><code>import gunicorn
  
  app = return_app()
  
  gunicorn(workers=1, ip=&quot;0.0.0.0&quot;, port=5000, app=app)
  </code></pre>
  <p>the most important part to me is the <code>app=app</code> part</p>
  <p>the main point is that I want to use the app object as an instance of Flask(). I want to directly give app object to gunicorn not throough addressing it in a string</p>
  <p><strong>What I have tried:</strong>
  I have opened gunicorn library <strong>main</strong>.py file</p>
  <pre><code>from gunicorn.app.wsgiapp import run
  run()
  </code></pre>
  <p>to see how it works but could not figure it out</p>
  <pre><code>def run():
      &quot;&quot;&quot;\
      The ``gunicorn`` command line runner for launching Gunicorn with
      generic WSGI applications.
      &quot;&quot;&quot;
      from gunicorn.app.wsgiapp import WSGIApplication
      WSGIApplication(&quot;%(prog)s [OPTIONS] [APP_MODULE]&quot;).run()
  </code></pre>