mirror of
https://github.com/jamesroberts/fastwsgi.git
synced 2025-12-19 13:19:32 -06:00
Add usage example to README
This commit is contained in:
32
README.md
32
README.md
@@ -2,18 +2,36 @@
|
||||
[](https://lgtm.com/projects/g/jamesroberts/fast-wsgi/context:python)
|
||||
|
||||
# Fast WSGI
|
||||
#### Note: Fast WSGI is still under development...
|
||||
|
||||
Fast WSGI is an ultra fast WSGI server for Python 3.
|
||||
|
||||
It is mostly written in C. It makes use of [libuv](https://github.com/libuv/libuv) and [llhttp](https://github.com/nodejs/llhttp) under the hood for blazing fast performance.
|
||||
|
||||
** Fast WSGI is still under development...
|
||||
|
||||
|
||||
## Example usage with Flask
|
||||
|
||||
```python
|
||||
import fast_wsgi
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def hello_world():
|
||||
return "Hello, World!", 200
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000)
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- Memory lifecycle management
|
||||
- Python object ref count tracking
|
||||
- WSGI app invoking
|
||||
- Test integration with flask app
|
||||
- Basic error handling
|
||||
|
||||
- Test integration with other frameworks (uWSGI, Django, etc)
|
||||
- Comprehensive error handling
|
||||
- Complete HTTP/1.1 compliance
|
||||
- Test on multiple platforms (Windows/MacOS)
|
||||
- Unit Tests
|
||||
@@ -225,8 +225,8 @@ void build_response(PyObject* wsgi_response, StartResponse* response, llhttp_t*
|
||||
PyObject* close_result = PyObject_CallObject(close, NULL);
|
||||
Py_XDECREF(close_result);
|
||||
}
|
||||
Py_DECREF(close);
|
||||
Py_DECREF(iter);
|
||||
Py_XDECREF(iter);
|
||||
Py_XDECREF(close);
|
||||
Py_XDECREF(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
14
fast_wsgi.py
14
fast_wsgi.py
@@ -2,7 +2,6 @@ import os
|
||||
import signal
|
||||
import _fast_wsgi
|
||||
|
||||
from flask import Flask, request
|
||||
|
||||
NUM_WORKERS = 4
|
||||
HOST = "0.0.0.0"
|
||||
@@ -33,15 +32,8 @@ def run_multi_process_server(app):
|
||||
os.kill(worker, signal.SIGINT)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/test", methods=["GET"])
|
||||
def hello_world():
|
||||
return {"message": "Hello, World!"}, 200
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def run(wsgi_app, host, port, backlog=1024):
|
||||
print("Starting server...")
|
||||
enable_logging = 0
|
||||
_fast_wsgi.run_server(wsgi_app, host, port, backlog, enable_logging)
|
||||
# run_multi_process_server(app)
|
||||
_fast_wsgi.run_server(app, HOST, PORT, BACKLOG, 1)
|
||||
|
||||
@@ -1 +1 @@
|
||||
wrk -t8 -c100 -d15 http://localhost:5000/test
|
||||
wrk -t8 -c100 -d15 http://localhost:5000
|
||||
2
run.sh
2
run.sh
@@ -1 +1 @@
|
||||
sudo python3 setup.py install; python3 fast_wsgi.py; fuser -k 5000/tcp;
|
||||
sudo python3 setup.py install; python3 testapp.py; fuser -k 5000/tcp;
|
||||
|
||||
15
testapp.py
Normal file
15
testapp.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import fast_wsgi
|
||||
import bjoern
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def hello_world():
|
||||
return "Hello, World!", 200
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000)
|
||||
bjoern.run(app, "0.0.0.0", 5000)
|
||||
Reference in New Issue
Block a user