[Twisted-web] newbie question

Jean-Paul Calderone exarkun at divmod.com
Mon Aug 18 11:29:54 EDT 2008

On Mon, 18 Aug 2008 10:15:46 -0500, arun chhetri <uhcops at gmail.com> wrote:
>So, does this means that twisted.web can only handle one request at a
>time,,,,, why It should do that.
> [snip]
>>> class Optional(resource.Resource):
>>> [snip]
>>>     def render(self,request):
>>> [snip]
>>>                     self.account['value'] = CalendarSource
>>>                     self.index = 1
>>>         request.redirect("/optional/Calendar")
>>>         return " "
>>> [snip]
>>> if __name__ == "__main__":
>>>     from twisted.internet import reactor
>>>     root = resource.Resource()
>>>     root.putChild('',HomePage())
>>>     root.putChild('optional',Optional())
>>>     site = server.Site(root)
>>>     reactor.listenTCP(8000,site)
>>>     reactor.run()

There is just one instance of `Optional´ in your application.  That
instance will be used to render the response to any request for
`/optional´.  The `Optional´ class also keeps state on itself which
appears to be associated with different users.  So whenever multiple
users make requests of your server, that single `Optional´ instance
is going to mix state from them together.  What you probably want to
do instead is have many instances of `Optional´, perhaps one per user
of your system.  This means keeping track of them somewhere and finding
the right one to use for any particular request.  For example, you might
keep a dict keyed on username somewhere and in a custom `getChild´
implementation find the right one and return it.


More information about the Twisted-web mailing list