My brain still thinks in asynchronous operations and I constantly have to unravel those thoughts and figure out how to express them, non-ideally, in a synchronous workflow. This is becoming tiring, and while I don't plan on leaving Django, I do plan on giving my brain a rest. Maybe I'll find a way to combine my two interests in the near future...
This is the result of the hour I spent relearning last night.
from twisted.web.server import Site, NOT_DONE_YETfrom twisted.web.static import Filefrom twisted.web.resource import Resourcefrom twisted.internet import reactorfrom twisted.internet.defer import Deferredclass ClockPage(Resource):isLeaf = Truedef render_GET(self, request):d = Deferred()@d.addCallbackdef _(r):request.write("<html><body>%s</body></html>" % (r,))request.finish()def get_time(r):d.callback(time.ctime())reactor.callLater(2, get_time, None)return NOT_DONE_YETresource = ClockPage()factory = Site(resource)reactor.listenTCP(8888, factory)