Server thread#835
Conversation
|
bumping this thread (pun intended!) going to play with this and would like to get it in |
|
I think easiest way is to write a function which returns a flask app because then people can wrap it with gunicorn. My opinion is just write the flask part and then others can use whichever webserver and deployment pattern they want |
|
@hhuuggoo can you show how this can be done? i think it'd be swell to incorporate an example of this in the docs. |
|
The way I got multithreading working with blaze was to create a new Flask app and register the blaze blueprint. I then take that new app create a singleton instance of a from gunicorn.app.base import BaseApplication
from metautils import Singleton
from my_code import build_app # the function that creates the app and registers the API
from my_code import gunicorn_config # gunicorn settings, workers, host, port, etc...
class app(BaseApplication, metaclass=Singleton()):
def load(self, *, _underlying=build_app(settings):
return _underlying
def load_config(self, *, _cfg=gunicorn_config):
for k, v in key_map(str.lower, _cfg).items():
if k in self.cfg.settings and v is not None:
self.cfg.set(k.lower(), v)
app.start()This lets us get multi-threading for free with gunicorn. |
|
Closing this PR as it's going stale. I think the threaded server issue is worth discussing. I'll open an issue. |
Servers don't have to block