This is an old thread, but responding in case anyone interested in django+thrift comes across this. Implementing Django/thrift server is not difficult to do and it has advantags over JSON/webservice, namely less overhead and simplified serialization/deserialization of strongly typed complex objects, which you will appreciate if deserializing into strongly typedl languages such as C++.
The easiest way is to create a new Django command that implements the server. (This is how other django modules with daemons such as Django-celery do it.) You can follow the directions in the Django documentation here:
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
In your command script, e.g. thrift_server.py, you put in the usual thrift server initialization:
import sys
from django.core.management.base import BaseCommand
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
#import thrift files here
#now define the service handler according to your thrift method declaration
class ServiceHandler:
def __init__(self):
pass
#self.log = {}
def thriftMethodName(self, arg):
print "hello world!"
#here you have access to anything in the django framework
return True
class Command(BaseCommand):
def handle(self, *args, **kwargs):
handler = ServiceHandler()
processor = SaleService.Processor(handler)
transport = TSocket.TServerSocket(port=9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
# You could do one of these for a multithreaded server
#server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
#server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
self.stdout.write('Starting thrift server...')
server.serve()
self.stdout.write('done.')
Then you can run the server like so:
(virtualenv) /django_project/ > python manage.py thrift_server
It will run as a daemon, use ctrl+c to exit.