1
# You can run this .tac file directly with:
2
# twistd -ny service.tac
5
This is an example .tac file which starts a webserver on port 8080 and
6
serves files from the current working directory.
8
The important part of this, the part that makes it a .tac file, is
9
the final root-level section, which sets up the object called 'application'
10
which twistd will look for
14
from twisted.application import service, internet
15
from twisted.web import static, server
19
Return a service suitable for creating an application object.
21
This service is a simple web server that serves files on port 8080 from
22
underneath the current working directory.
24
# create a resource to serve static files
25
fileServer = server.Site(static.File(os.getcwd()))
26
return internet.TCPServer(8080, fileServer)
28
# this is the core part of any tac file, the creation of the root-level
30
application = service.Application("Demo application")
32
# attach the service to its parent application
33
service = getWebService()
34
service.setServiceParent(application)