DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests.
("django-admin and manage.py")
don't use this server in anything resembling a production environment. It’s intended only for use while developing.
Django Tutorial
$ # Assumes you installed the project
$ twist web --wsgi mysite.wsgi.application
$ # From work directory
$ PYTHONPATH=mysite twist web --wsgi mysite.wsgi.application
watchmedo shell-command \
--patterns="*.py;*.txt" --recursive \
--command \
'PYTHONPATH=mysite twist web --wsgi mysite.wsgi.application' \
mysite
Put in manage.py
--port
argument is magical.
tcp:8001
txsni:/path/to/certs:tcp:8080
txacme:/path/to/certs:tcp:8888
pool = threadpool.ThreadPool(name="WSGI",
minThreads=3,
maxThreads=4)
reactor.callWhenRunning(pool.start)
reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
application = twemo.wsgi.application
wsgi_resource = wsgi.WSGIResource(reactor, pool, application)
site = server.Site(root)
# Disable HTTP/2
site.acceptableProtocols = lambda: [b'http/1.1']
$ pex -o twist.pex -m twisted twisted myproject $ scp twist.pex machine2:/home/me/twist.pex $ ssh /home/me/twist.pex web --wsgi myproject.wsgi.application
class DelegatingResource(resource.Resource):
def __init__(self, wsgi_resource):
resource.Resource.__init__(self)
self.wsgi_resource = wsgi_resource
def getChild(self, name, request):
request.prepath = []
request.postpath.insert(0, name)
return self.wsgi_resource
@interface.implementer(service.IServiceMaker, plugin.IPlugin)
class ServiceMaker(object):
description = tapname = "simple"
class options(usage.Options):
optParameters = [["port", None, None, ""]]
def makeService(self, options):
pool = threadpool.ThreadPool()
reactor.callWhenRunning(pool.start)
reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
wsgi = wsgi.WSGIResource(reactor, pool, twemo.wsgi.application)
root = DelegatingResource(wsgi)
root.putChild('static', static.File('.'))
return strports.service(options['port'], server.Site(root))
serviceMaker = ServiceMaker()
ts = internet.TimerService(30, print, "---MARK---")
Dynamically set parameters (e.g., A/B experiment parameters) from