0

I am trying to run QUART and NATS client in one application. Using this code for nats part [https://github.com/nats-io/stan.py/issues/12#issuecomment-400865266][1]

My main function contains:

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    loop.run_until_complete(serve(app, config))
    loop.run_until_complete(run_nats(loop))
    loop.close()

But it just runs QUART and nats is blocked. How can I solve this?

Information:

  • Python 3.9
  • asyncio-nats-client 0.11.4
  • Quart 0.11.4

1 Answers1

0

The loop.run_until_complete line will run and block until it completes, in this case running first Quart (until it completes) and then nats. To run both concurrently I typically run use gather,

loop.run_until_complete(asyncio.gather(serve(app, config), run_nats(loop))
pgjones
  • 6,044
  • 1
  • 14
  • 12