Comments (17)
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).
from hypercorn.
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.
from hypercorn.
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.
from 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.
from hypercorn.
In this case serve
is a coroutine, 1ecfcc3 so the run_until_complete shouldn't be an issue.
I see it as an addition to the "before_serving" and "after_serving" decorators.
So when would it be called? Some options I can think of are, after the first request, after every request, periodically (what period).
from hypercorn.
Is this serve()
in the latest hypercorn version only compatible with quart 0.7.x? I can't make it work with quart 0.6 version on python 3.6.
from hypercorn.
It should work with 0.6 on Python 3.6, what is the error you are getting? (I've not released it yet though).
from hypercorn.
Getting something like this
File "http2_server.py", line 203, in run
loop.run_until_complete(serve(app, config))
File "/usr/lib/python3.6/asyncio/base_events.py", line 473, in run_until_complete
return future.result()
File "xyz/tmp/hypercorn/hypercorn/asyncio/__init__.py", line 31, in serve
await worker_serve(app, config)
File "xyz/tmp/hypercorn/hypercorn/asyncio/run.py", line 133, in worker_serve
await lifespan.wait_for_startup()
File "xyz/tmp/hypercorn/hypercorn/asyncio/lifespan.py", line 47, in wait_for_startup
await asyncio.wait_for(self.startup.wait(), timeout=self.config.startup_timeout)
File "/usr/lib/python3.6/asyncio/tasks.py", line 362, in wait_for
raise futures.TimeoutError()
concurrent.futures._base.TimeoutError
Runnning on:
Python 3.6.5
Quart 0.6.11
Hypercorn 0.4.6 (from master)
from hypercorn.
Here's an update... Enabled some error logging and got:
ASGI Framework Lifespan error, continuing without Lifespan support
Quart 0.6 doesn't seem to have the "lifespan"
scope type.
from hypercorn.
I've just tested this and it works ok for me (the ASGI Framework Lifespan error, continuing without Lifespan support
is a warning that is safe to ignore with Quart 0.6). I think you likely have a before_serving
function that doesn't complete e.g. the first snippet in this thread. Could you paste your before_serving function(s)?
from hypercorn.
I removed any decorators I had:
config = Config()
config.error_log_target = '-'
config.certfile = certfile
config.keyfile = keyfile
config.bind = ["127.0.0.1:8002"]
loop = asyncio.get_event_loop()
loop.run_until_complete(serve(app, config))
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.
from hypercorn.
I see, it was a race condition - I've fixed it in 16b0ae8 could you see if it works for you?
from hypercorn.
Works now!
Back to my initial ask, I poked around the code a bit and noticed that you have a shutdown_event
argument that I could use, but it doesn't bubble up to serve()
. Any reason why it doesn't?
https://github.com/pgjones/hypercorn/blob/master/hypercorn/asyncio/run.py#L128
Also, would it make sense to have a similar startup_event
or something like that, that's set when the server is ready to take new connections?
from hypercorn.
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).
from hypercorn.
But would it make sense to expose shutdown_event
kwarg to serve
coro?
from hypercorn.
I don't think so as I'd like to keep the public API as simple as possible. You could use the worker_serve
coro though (basically serve with the shutdown_event).
from hypercorn.
Closing for now
from hypercorn.
Related Issues (20)
- Getting permission Error [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions when running FastAPI in IIS
- Need clarification on trusted hops HOT 1
- Reload up to date SSL certificates without restarting server?
- pytest-cov / pytest-sugar not included in pyproject.toml
- TCP server keep-alive times out even though data is being received. HOT 2
- Can we please get a new release? HOT 1
- ProxyFixMiddleware throws exception when X-Forwarded-Host is present HOT 1
- Unexpected "shutdown without Lifespan support" error on Hypercorn 0.17.3 HOT 1
- Cannot start WSGI application using Dispatcher middleware to support both FastAPI and Flash app at the same time. HOT 1
- It seems hypercorn is not closing connections properly HOT 12
- ProxyFixMiddleware: Turns out GCP LBs and possibly AWS LBs only have one value in `x-forwarded-proto` HOT 1
- Opentelemetry Tracing + Logging Issue
- error `hypercorn --config python:hypercorn_config.config` HOT 1
- Hypercorn processes daemon property fails multiprocessing.Process / concurrent.futures.ProcessPoolExecutor HOT 1
- Type hint for check_multiprocess_shutdown_event is confusing for mypy
- feat: configure `hypercorn` with environment variables HOT 1
- Documentation needs an http2 example
- AttributeError: '_UnixSelectorEventLoop' object has no attribute 'shutdown_default_executor'
- HTTP2 Trailers not being sent HOT 2
- asgi: import app and start app in same event loop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hypercorn.