File: multi-threaded.txt

package info (click to toggle)
quixote 2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,036 kB
  • ctags: 1,131
  • sloc: python: 5,935; ansic: 1,436; makefile: 87; sh: 23
file content (36 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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, root_namespace, config=None):
          Publisher.__init__(self, root_namespace, config)
          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.