emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.86k stars 83 forks source link

Ability to use Granian with asyncio.create_task #208

Closed XavierGeerinck closed 9 months ago

XavierGeerinck commented 9 months ago

Hi!

For my application I am trying out the Granian server. However, for testing it, I would like to spin it up in the background through asyncio.create_task(server.start())

I currently see the server starting, but it blocking the entire event loop. Is there any known way of making it not block the event loop?

gi0baro commented 9 months ago

@XavierGeerinck I'm not sure what you're referring to by server.start, as Granian interface doesn't have a start method. Also, Granian doesn't expose coroutines, so I'm not sure why you want to run sync functions in an event loop.

Probably you want to run Granian.serve in a separated thread, but without additional context is hard for me to suggest viable solutions here.