from twisted.web import server, resource
from twisted.internet import reactor, defer
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
return "<html>Hello, world!</html>"
def call_me():
d = defer.Deferred()
print "Get something"
d.callback("success")
return d
def run_web(_):
print "run_web"
site = server.Site(Simple())
reactor.listenTCP(8080, site)
d = call_me()
d.addCallback(run_web)
reactor.run()
--
Alex
08.09.15 17:51, Nagy, Attila пишет:
Hi,
I wonder, if I have this example program:
https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#site-objects
how do I initialize an external resource (like a dictionary,
which is fetched from a database) with asynchronous twisted
tools, but before the HTTP server starts listening on its port?
The goal here is that the HTTP server shouldn't start until it
can fetch the desired data. Of course I can do this in a
synchronous way, but it feels so unnatural and bad practice to
fetch the same stuff synchronously on initialization and
asynchronously when the program/reactor is running (often with
different libraries).
Thanks,
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python