1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Worker Models
19 =============
20
21 The modules in this package implement the different ways of worker
22 pool models. Currently there are:
23
24 threaded
25 There's one single process managing a threadpool. Accepted sockets
26 are dispatched to a single worker thread.
27 """
28 __author__ = u"Andr\xe9 Malo"
29 __docformat__ = "restructuredtext en"
30
31 from wtf.config import ConfigurationError
32
33
35 """
36 Interface for worker implementations
37
38 :IVariables:
39 - `sig_hup`: Should SIGHUP restart the worker?
40
41 :Types:
42 - `sig_hup`: ``bool``
43 """
44
46 """
47 Initialization
48
49 :Parameters:
50 - `config`: The application config
51 - `opts`: Command line option container
52 - `args`: Fixed commandline arguments
53
54 :Types:
55 - `config`: `wtf.config.Config`
56 - `opts`: ``optparse.OptionContainer``
57 - `args`: ``list``
58 """
59
60 - def setup(self, sock, prerun, parent_cleanup, child_cleanup):
61 """
62 Setup the worker pool
63
64 :Parameters:
65 - `sock`: The main listener socket
66 - `prerun`: Pre-runner (called right after finishing the setup), called
67 once
68 - `parent_cleanup`: Parent cleanup, if the implementation forks, called
69 once
70 - `child_cleanup`: Child cleanup, if the implementation forks, called
71 every time
72
73 :return: The worker pool
74 :rtype: `WorkerPoolInterface`
75 """
76
77
79 """ Interface for worker pools """
80
83
85 """ Shutdown the pool """
86
87
89 """
90 Create the worker instance selected by configuration
91
92 :Parameters:
93 - `config`: configuration
94 - `opts`: Option container
95 - `args`: Fixed arguments
96
97 :Types:
98 - `config`: `config.Config`
99 - `opts`: ``optparse.OptionContainer``
100 - `args`: ``list``
101
102 :return: worker instance
103 :rtype: `WorkerInterface`
104 """
105 self = factory
106
107 model = opts.workermodel or config.wtf.workermodel
108 if model not in self.models:
109 raise ConfigurationError("Unknown workermodel %r" % (model,))
110
111 return self.models[model](config, opts, args)
112 factory.models = {}
113
115 """
116 Register a worker implementation
117
118 :Parameters:
119 - `name`: The name (in the config)
120 - `klass`: The implementation class
121
122 :Types:
123 - `name`: ``str``
124 - `klass`: `WorkerInterface`
125 """
126 factory.models[name] = klass
127