New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A "while_serving" decorator? #13
Comments
Not sure what the use case is here, why would you want the server to die completely? (Wouldn't you want it to close idle connections but listen for new ones). |
I need to programmatically spin up a sever and a client to test an external load balancer. Having a server that runs forever is not really an option. |
Could you do something like this? def shutdown():
raise Shutdown() # Or maybe sys.exit?
loop = asyncio.get_event_loop()
loop.call_later(1, shutdown)
loop.run_until_complete(serve(app, config)) I'm not sure this is a common enough use case to be part of Hypercorn. |
One issue with that might be that "serve" would want to call run_forever at some point which is not possible, since the loop is already running. I don't think it'd be too complicated to add, I see it as an addition to the "before_serving" and "after_serving" decorators. |
In this case
So when would it be called? Some options I can think of are, after the first request, after every request, periodically (what period). |
Is this |
It should work with 0.6 on Python 3.6, what is the error you are getting? (I've not released it yet though). |
Getting something like this
Runnning on:
|
Here's an update... Enabled some error logging and got: Quart 0.6 doesn't seem to have the |
I've just tested this and it works ok for me (the |
I removed any decorators I had:
How did you test it and how do you know it's working? The timeout exception comes after 1-2 minutes and until then any requests coming in are being refused. |
I see, it was a race condition - I've fixed it in 16b0ae8 could you see if it works for you? |
Works now! Also, would it make sense to have a similar |
I think your use case might be too specific for Hypercorn to support directly, I think the before/after serving functionality should cover almost all use. I'm actually not sure how it doesn't cover your case (I think it should). |
But would it make sense to expose |
I don't think so as I'd like to keep the public API as simple as possible. You could use the |
Closing for now |
What do you think about having another decorator like this that would allow you to control when server is shut down
This is useful when you need a server up for to X seconds, rather than forever. I think you could spin up a thread with a timer and have that call loop.stop() when done, but it's dirty.
Great for testing!
The text was updated successfully, but these errors were encountered: