Skip to content

Commit

Permalink
export application object when using gunicorn or wsgi, fix #20
Browse files Browse the repository at this point in the history
For higher concurrency (if possible at all with SQLite), gevent will be used if
installed (`pip install gevent`). Furthermore, `weave-minimal` exports an
*application* object for uWSGI and Gunicorn, e.g.:

```bash
$ env ENABLE_REGISTRATION=1 DATA_DIR=/var/lib/... gunicorn weave -b localhost:1234
```

Do *not* use multiple processes to run `weave-minimal`. The code does not
acquire inter-process locks on the database and I have no plans to add a IPC
concurrency pattern to the rather simple code base (programmer's lame excuse,
I know).
  • Loading branch information
posativ committed Dec 7, 2013
1 parent 10d55ad commit 01356b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ parameters and a short description.
$ weave-minimal --enable-registration
* Running on http://127.0.0.1:8080/

For high concurrency (if possible at all with SQLite), gevent will be used if
installed (`pip install gevent`).

To run weave-minimal as a daemon, consider this SysVinit script:

```bash
Expand Down Expand Up @@ -195,3 +192,19 @@ For nginx the code to add would be:
ssl_ciphers HIGH:!aNULL:!MD5:RC4+RSA;
# ...
}

Deployment
----------

For higher concurrency (if possible at all with SQLite), gevent will be used if
installed (`pip install gevent`). Furthermore, `weave-minimal` exports an
*application* object for uWSGI and Gunicorn, e.g.:

```bash
$ env ENABLE_REGISTRATION=1 DATA_DIR=/var/lib/... gunicorn weave -b localhost:1234
```

Do *not* use multiple processes to run `weave-minimal`. The code does not
acquire inter-process locks on the database and I have no plans to add an IPC
concurrency pattern to the rather simple code base (programmer's lame excuse,
I know).
10 changes: 8 additions & 2 deletions weave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,12 @@ def initialize(self, uid, password):

print('[info] database for `%s` created at `%s`' % (uid, dbpath))


def dispatch(self, request, start_response):
adapter = url_map.bind_to_environ(request.environ)
try:
handler, values = adapter.match()
return handler(self, request.environ, request, **values)
except NotFound as e:
except NotFound:
return Response('Not Found', 404)
except HTTPException as e:
return e
Expand Down Expand Up @@ -270,3 +269,10 @@ def main():
WSGIServer((options.host, options.port), app).serve_forever()
except ImportError:
run_simple(options.host, options.port, app, use_reloader=options.reloader, threaded=True)


if sys.argv[0].endswith(("gunicorn", "uwsgi")):
application = make_app(
data_dir=os.environ.get("DATA_DIR", ".data/"),
base_url=os.environ.get("BASE_URL", None),
register=bool(os.environ.get("ENABLE_REGISTRATION", "0")))

0 comments on commit 01356b8

Please sign in to comment.