durusmail: quixote-users: Making Quixote work in a threaded Web server.
Making Quixote work in a threaded Web server.
2002-10-04
2002-10-04
2002-10-04
2002-10-04
2002-10-06
2002-10-07
2002-10-16
2002-10-16
2002-10-16
2002-10-16
2002-10-17
2002-10-17
2002-10-17
2002-10-16
2002-10-16
Making Quixote work in a threaded Web server.
Titus Brown
2002-10-04
Hi, folks,

I've made Quixote run in a multi-threaded environment, and this work has
suggested a few changes that I'd like to make in the distribution.  I don't
think any of them are particularly unreasonable ;).

It seems like some reorganization along these lines has already been done
in 0.5.1, but I haven't seen the code yet; these suggestions are all made
against the 0.5 codebase.

* Can Publisher.start_time be moved to HTTPRequest?

* At the end of 'try_publish', can the _request object be invalidated in
        some manner?  (Preferably in a function that I can override in a
        subclass of Publisher, like parse_request() but for deleting the
        request.)  The distinction between this and the finish_*_request
        functions is that this function should ALWAYS be called independently
        of the session manager etc. stuff.

        I would suggest 'clear_request' or something like that; this is
        what I have implemented.  It should be executed before output is
        sent.

        Another option is to have a 'clear' function on the HTTPRequest
        object to let it know that it's done, but this isn't really the
        style of the existing code.

* Can get_request call a function on _publisher, i.e. make _request be a
        member of Publisher grabbed through an accessor fn?  I can't
        override the functionality of get_request, as-is, because it is
        a module function.

        It would also be nice to have parse_request() set _request through
        an accessor function, for the same reason.  This could be in
        either start_request() or parse_request().

        I have put it in parse_request because that is called by
        SessionPublisher; start_request seems like a better place to
        put it, but that is not called by SessionPublisher.

Eventually I would like to be able to add a mix-in -- say,
'ThreadedPublisherMixin' -- so that one can e.g. have an
AppSpecificPublisher that subclasses from both SessionPublisher and
ThreadedPublisherMixin.  This way people who don't want to deal with
threads don't have to, and people who really need to, can.

For example, in my Cartwheel Web site, I have a CartwheelPublisher that
(among other things) has the following three functions:

---
    def set_request(self, request):
        id = thread.get_ident()
        self.request_dict[id] = request

    def get_request(self):
        id = thread.get_ident()
        return self.request_dict[id]

    def clear_request(self, request):
        id = thread.get_ident()
        if self.request_dict.has_key(id):
            del self.request_dict[id]
---

These three function definitions are sufficient (in the context of the
other changes) to implement a one-Publisher-many-HTTPRequest Quixote
system.

Context diffs implementing these changes against Quixote 0.5 are attached.
Only publish.py is affected.

thanks,
--titus
reply