MCPcopy Index your code
hub / github.com/python/cpython / Server

Class Server

Lib/multiprocessing/managers.py:143–469  ·  view source on GitHub ↗

Server class which runs in a process controlled by a manager object

Source from the content-addressed store, hash-verified

141#
142
143class Server(object):
144 '''
145 Server class which runs in a process controlled by a manager object
146 '''
147 public = ['shutdown', 'create', 'accept_connection', 'get_methods',
148 'debug_info', 'number_of_objects', 'dummy', 'incref', 'decref']
149
150 def __init__(self, registry, address, authkey, serializer):
151 if not isinstance(authkey, bytes):
152 raise TypeError(
153 "Authkey {0!r} is type {1!s}, not bytes".format(
154 authkey, type(authkey)))
155 self.registry = registry
156 self.authkey = process.AuthenticationString(authkey)
157 Listener, Client = listener_client[serializer]
158
159 # do authentication later
160 self.listener = Listener(address=address, backlog=128)
161 self.address = self.listener.address
162
163 self.id_to_obj = {'0': (None, ())}
164 self.id_to_refcount = {}
165 self.id_to_local_proxy_obj = {}
166 self.mutex = threading.Lock()
167
168 def serve_forever(self):
169 '''
170 Run the server forever
171 '''
172 self.stop_event = threading.Event()
173 process.current_process()._manager_server = self
174 try:
175 accepter = threading.Thread(target=self.accepter)
176 accepter.daemon = True
177 accepter.start()
178 try:
179 while not self.stop_event.is_set():
180 self.stop_event.wait(1)
181 except (KeyboardInterrupt, SystemExit):
182 pass
183 finally:
184 if sys.stdout != sys.__stdout__: # what about stderr?
185 util.debug('resetting stdout, stderr')
186 sys.stdout = sys.__stdout__
187 sys.stderr = sys.__stderr__
188 sys.exit(0)
189
190 def accepter(self):
191 while True:
192 try:
193 c = self.listener.accept()
194 except OSError:
195 continue
196 t = threading.Thread(target=self.handle_request, args=(c,))
197 t.daemon = True
198 t.start()
199
200 def _handle_request(self, c):

Callers 1

get_serverMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…