title: How to use workers with hypercorn serve?
body: <p>I want to start my FastAPI app using hypercorn from main.py.</p>
  <p>I used this command to start the server manually:</p>
  <p><code>hypercorn --access-logformat &quot;%(R)s %(s)s %(st)s %(D)s %({Header}o)s&quot; --access-logfile - -b 0.0.0.0:8000 -w 9 app:app</code></p>
  <p>Now I need to do the same thing from my code. First attempt was:</p>
  <pre><code>from hypercorn.config import Config
  from hypercorn.asyncio import serve
  
  from api.app import app # app = FastAPI()
  
  config = Config()
  config.bind = ['0.0.0.0:8000']
  config.access_log_format = '%(R)s %(s)s %(st)s %(D)s %({Header}o)s'
  config.accesslog = mainLog # mainLog = logging.getLogger('main')
  config.loglevel = 'INFO'
  
  asyncio.run(serve(app, config))
  </code></pre>
  <p>I've tried to set <code>config.workers = 9</code> , but in response I've got:</p>
  <pre><code>Warning: The config `workers` has no affect when using serve
    warnings.warn(&quot;The config `workers` has no affect when using serve&quot;, Warning)
  </code></pre>
  <p>Then I rewrite my code to this:</p>
  <pre><code>import logging
  import asyncio
  
  from hypercorn.config import Config
  from hypercorn.asyncio import serve
  
  from api.app import app
  
  
  mainLog = logging.getLogger('main')
  ...
  
  async def main(app, config):
      await  serve(app, config)
  
  if __name__ == &quot;__main__&quot;:
      config = Config()
      config.bind = ['0.0.0.0:8000']
      config.access_log_format = &quot;%(R)s %(s)s %(st)s %(D)s %({Header}o)s&quot;
      config.accesslog = mainLog
      config.loglevel = 'INFO'
      config.worker_class = 'asyncio'
      config.workers = 9
      try:
          loop = asyncio.get_event_loop()
          loop.run_until_complete(main(app, config))
  
      except:
          mainLog.exception('Fail to start server')
  </code></pre>
  <p>But I still got the same warning.
  <a href="https://pgjones.gitlab.io/hypercorn/how_to_guides/api_usage.html" rel="nofollow noreferrer">Documentation</a> says:</p>
  <blockquote>
  <p>... it is possible to use Hypercorn programmatically via the serve function available for either the asyncio or trio Workers (note the asyncio serve can be used with uvloop).</p>
  </blockquote>
  <p>Am I misunderstand the docs? I have lack of knowledge in this area, so please help me.</p>