Thrift server using gunicorn
Project description
gunicorn_thrift
===============
[![Build Status](https://travis-ci.org/eleme/gunicorn_thrift.svg?branch=master)](https://travis-ci.org/eleme/gunicorn_thrift)
Thrift app and worker for gunicorn!
## Why?
* graceful reload/shutdown.
* manage worker number at runtime.
* and everything else `gunicorn` has to offer.
## Supported Platforms
* Python 2.7, all worker classes
* Python 3.2+, `thriftpy_sync` worker class (neither gevent nor code generated
using the Thrift toolkit are supported on Python 3)
## Examples
### Using `thrift`
1. Generate thrift files:
```bash
% thrift --out tests/pingpong_sdk --gen py:new_style,utf8strings tests/pingpong.thrift
```
2. Write thrift app.
```python
#! /usr/bin/env python
# tests/app.py
# -*- coding: utf-8 -*-
from pingpong_sdk.pingpong import PingService
class PingpongServer(object):
def ping(self):
if os.environ.get('about_to_shutdown') == '1':
raise PingService.AboutToShutDownException
return "pong"
app = PingService.Processor(PingpongServer())
```
3. Fire up app.
```bash
% gunicorn_thrift tests.app:app -k thrift_sync
% gunicorn_thrift tests.app:app -k thrift_gevent
```
### Using `thriftpy`
1. Write thrift app.
```python
#! /usr/bin/env python
# tests/app.py
# -*- coding: utf-8 -*-
import thriftpy
from thriftpy.thrift import TProcessor
class PingPongDispatcher(object):
def ping(self):
return "pong"
pingpong_thrift = thriftpy.load("pingpong.thrift")
app = TProcessor(pingpong_thrift.PingService, PingPongDispatcher())
```
2. Fire up app.
```bash
% gunicorn_thrift tests.thriftpy_app:app -k thriftpy_sync \
--thrift-protocol-factory \
thriftpy.protocol:TCyBinaryProtocolFactory \
--thrift-transport-factory \
thriftpy.transport:TCyBufferedTransportFactory
```
## Configs
### Workers
Parameter: `-k`, `--worker-class`
Config file: `worker_class`
Default 2.7: `thrift_sync`
Default 3.2+: `thriftpy_sync`
There are 4 types of workers avaiable.
* `thrift_sync`: sync worker.
* `thrift_gevent`: gevent worker.
* `thriftpy_sync`: sync worker, adapted for [`thriftpy`](https://github.com/eleme/thriftpy)
* `thriftpy_gevent`: gevent worker, adapted for [`thriftpy`](https://github.com/eleme/thriftpy)
note: If you want to use `thriftpy_sync` or `thriftpy_gevent`, make sure the following:
* Version of `thriftpy` should be higher than `0.1.10`.
* `--thrift-protocol-factory` should be set to either `thriftpy.protocol:TCyBinaryProtocolFactory` or `thriftpy.protocol:TBinaryProtocolFactory`
* `--thrift-transport-factory` should be set to either `thriftpy.transport:TCyBufferedTransportFactory` or `thriftpy.transport:TBufferedTransportFactory`
### Transport factory
The transport factory to use for handling connections.
Parameter: `--thrift-transport-factory`
Config file: `thrift_transport_factory`
Default 2.7: `thrift.transport.TTransport:TBufferedTransportFactory`
Default 3.2+: `thriftpy.transport:TBufferedTransportFactory`
### Protocol factory
The protocol factory to use for parsing requests.
Parameter: `--thrift-protocol-factory`
Config file: `thrift_protocol_factory`
Default 2.7: `thrift.protocol.TBinaryProtocol:TBinaryProtocolAcceleratedFactory`
Default 3.2+: `thriftpy.protocol:TBinaryProtocolFactory`
### Client timeout
Seconds to timeout a client if it is silent after this duration.
Parameter: `--thrift-client-timeout`
Config file: `thrift_client_timeout`
Default: `None` (Never time out a client)
===============
[![Build Status](https://travis-ci.org/eleme/gunicorn_thrift.svg?branch=master)](https://travis-ci.org/eleme/gunicorn_thrift)
Thrift app and worker for gunicorn!
## Why?
* graceful reload/shutdown.
* manage worker number at runtime.
* and everything else `gunicorn` has to offer.
## Supported Platforms
* Python 2.7, all worker classes
* Python 3.2+, `thriftpy_sync` worker class (neither gevent nor code generated
using the Thrift toolkit are supported on Python 3)
## Examples
### Using `thrift`
1. Generate thrift files:
```bash
% thrift --out tests/pingpong_sdk --gen py:new_style,utf8strings tests/pingpong.thrift
```
2. Write thrift app.
```python
#! /usr/bin/env python
# tests/app.py
# -*- coding: utf-8 -*-
from pingpong_sdk.pingpong import PingService
class PingpongServer(object):
def ping(self):
if os.environ.get('about_to_shutdown') == '1':
raise PingService.AboutToShutDownException
return "pong"
app = PingService.Processor(PingpongServer())
```
3. Fire up app.
```bash
% gunicorn_thrift tests.app:app -k thrift_sync
% gunicorn_thrift tests.app:app -k thrift_gevent
```
### Using `thriftpy`
1. Write thrift app.
```python
#! /usr/bin/env python
# tests/app.py
# -*- coding: utf-8 -*-
import thriftpy
from thriftpy.thrift import TProcessor
class PingPongDispatcher(object):
def ping(self):
return "pong"
pingpong_thrift = thriftpy.load("pingpong.thrift")
app = TProcessor(pingpong_thrift.PingService, PingPongDispatcher())
```
2. Fire up app.
```bash
% gunicorn_thrift tests.thriftpy_app:app -k thriftpy_sync \
--thrift-protocol-factory \
thriftpy.protocol:TCyBinaryProtocolFactory \
--thrift-transport-factory \
thriftpy.transport:TCyBufferedTransportFactory
```
## Configs
### Workers
Parameter: `-k`, `--worker-class`
Config file: `worker_class`
Default 2.7: `thrift_sync`
Default 3.2+: `thriftpy_sync`
There are 4 types of workers avaiable.
* `thrift_sync`: sync worker.
* `thrift_gevent`: gevent worker.
* `thriftpy_sync`: sync worker, adapted for [`thriftpy`](https://github.com/eleme/thriftpy)
* `thriftpy_gevent`: gevent worker, adapted for [`thriftpy`](https://github.com/eleme/thriftpy)
note: If you want to use `thriftpy_sync` or `thriftpy_gevent`, make sure the following:
* Version of `thriftpy` should be higher than `0.1.10`.
* `--thrift-protocol-factory` should be set to either `thriftpy.protocol:TCyBinaryProtocolFactory` or `thriftpy.protocol:TBinaryProtocolFactory`
* `--thrift-transport-factory` should be set to either `thriftpy.transport:TCyBufferedTransportFactory` or `thriftpy.transport:TBufferedTransportFactory`
### Transport factory
The transport factory to use for handling connections.
Parameter: `--thrift-transport-factory`
Config file: `thrift_transport_factory`
Default 2.7: `thrift.transport.TTransport:TBufferedTransportFactory`
Default 3.2+: `thriftpy.transport:TBufferedTransportFactory`
### Protocol factory
The protocol factory to use for parsing requests.
Parameter: `--thrift-protocol-factory`
Config file: `thrift_protocol_factory`
Default 2.7: `thrift.protocol.TBinaryProtocol:TBinaryProtocolAcceleratedFactory`
Default 3.2+: `thriftpy.protocol:TBinaryProtocolFactory`
### Client timeout
Seconds to timeout a client if it is silent after this duration.
Parameter: `--thrift-client-timeout`
Config file: `thrift_client_timeout`
Default: `None` (Never time out a client)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gunicorn_thrift-0.2.1.tar.gz
(5.9 kB
view details)
Built Distributions
File details
Details for the file gunicorn_thrift-0.2.1.tar.gz
.
File metadata
- Download URL: gunicorn_thrift-0.2.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6034045f3958ae933a20bbb54f69e117b5ddb21c9a2dffba4864b89f2f98fce9 |
|
MD5 | 34c9e12d08a540e9b50d78f3ea306610 |
|
BLAKE2b-256 | d8a865a9492ebe9c4babdd6224063681cb4c1fe306a84de9fd85ba47e84669d5 |
File details
Details for the file gunicorn_thrift-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: gunicorn_thrift-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c0751e26530af3eb0184031dd530d316f40222f4a8a4270877ef5859381489e |
|
MD5 | 41d2076fedbfe8280c4a5358c5ca3d3e |
|
BLAKE2b-256 | 5c602e8672d748debaa20d5460dbb4ab38acbcbe38f15ffd6ffa90abf7230970 |
File details
Details for the file gunicorn_thrift-0.2.1-py2-none-any.whl
.
File metadata
- Download URL: gunicorn_thrift-0.2.1-py2-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87490367f81398441dc983d995d49ca87e6e062003e419c2ba30d444211b9a42 |
|
MD5 | 323667b3ac9795ffdb466c8f9de47011 |
|
BLAKE2b-256 | e7638003df0070c0f3a5e0cebc9fac948b11626e77b664691799e760cf9a644c |