Skip to content

Server thread#835

Closed
mrocklin wants to merge 4 commits into
blaze:masterfrom
mrocklin:server-thread
Closed

Server thread#835
mrocklin wants to merge 4 commits into
blaze:masterfrom
mrocklin:server-thread

Conversation

@mrocklin

Copy link
Copy Markdown
Member

Servers don't have to block

In [1]: from blaze import Server

In [2]: server = Server({})

In [3]: server.run(separate_thread=True)
Out[3]: <FunctionRunner(Thread-1, started 139788731410176)>
 * Running on http://127.0.0.1:6363/

In [4]: # Control returned

@cpcloud cpcloud added this to the Release 0.8 milestone Dec 21, 2014
@cpcloud

cpcloud commented Mar 8, 2015

Copy link
Copy Markdown
Member

bumping this thread (pun intended!)

going to play with this and would like to get it in

@cpcloud cpcloud self-assigned this Mar 8, 2015
@hhuuggoo

hhuuggoo commented Mar 8, 2015

Copy link
Copy Markdown
Contributor

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

@cpcloud

cpcloud commented Mar 8, 2015

Copy link
Copy Markdown
Member

@hhuuggoo can you show how this can be done? i think it'd be swell to incorporate an example of this in the docs.

@mrocklin

mrocklin commented Mar 8, 2015

Copy link
Copy Markdown
Member Author

@hhuuggoo

hhuuggoo commented Mar 8, 2015

Copy link
Copy Markdown
Contributor

@cpcloud cpcloud modified the milestones: Release 0.8, Release 0.9 Mar 13, 2015
@llllllllll

Copy link
Copy Markdown
Member

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 gunicorn.app.base.BaseApplication and call the run method on this new server object. An example looks like:

    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.

@cpcloud

cpcloud commented Jun 26, 2015

Copy link
Copy Markdown
Member

Closing this PR as it's going stale. I think the threaded server issue is worth discussing. I'll open an issue.

@cpcloud cpcloud closed this Jun 26, 2015
@cpcloud cpcloud mentioned this pull request Jun 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants