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.
Greg Ward
2002-10-16
On 16 October 2002, I said:
> Probably belongs in documentation -- I'm reluctant to include code that
> we don't use and isn't widely used by others.  I'll go start
> doc/multi-threaded.txt now.

All right, here's doc/multi-threaded.txt.  Titus, please review it
carefully!  I did things slightly differently from your code.

------------------------------------------------------------------------
Multi-Threaded Quixote Applications
===================================

Starting with Quixote 0.6, it's possible to write multi-threaded Quixote
applications.  In previous versions, Quixote stored the current
HTTPRequest object in a global variable, meaning that processing
multiple requests in the same process simultaneously was impossible.

However, the Publisher class as shipped still can't handle multiple
simultaneous requests; you'll need to subclass Publisher to make it
re-entrant.  Here's a starting point::

  import thread
  from quixote.publish import Publisher

  [...]

  class ThreadedPublisher (Publisher):
      def __init__ (self):
          self._request_dict = {}

      def _set_request(self, request):
          self._request_dict[thread.get_ident()] = request

      def _clear_request(self):
          try:
              del self._request_dict[thread.get_ident()]
          except KeyError:
              pass

      def get_request(self):
          return self._request_dict.get(thread.get_ident())

Using ThreadedPublisher, you now have one current request per thread,
rather than one for the entire process.
------------------------------------------------------------------------

--
Greg Ward - software developer                gward@mems-exchange.org
MEMS Exchange                            http://www.mems-exchange.org

reply