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

Function _run_test_server

Lib/test/test_asyncio/utils.py:165–197  ·  view source on GitHub ↗
(*, address, use_ssl=False, server_cls, server_ssl_cls)

Source from the content-addressed store, hash-verified

163
164
165def _run_test_server(*, address, use_ssl=False, server_cls, server_ssl_cls):
166
167 def loop(environ):
168 size = int(environ['CONTENT_LENGTH'])
169 while size:
170 data = environ['wsgi.input'].read(min(size, 0x10000))
171 yield data
172 size -= len(data)
173
174 def app(environ, start_response):
175 status = '200 OK'
176 headers = [('Content-type', 'text/plain')]
177 start_response(status, headers)
178 if environ['PATH_INFO'] == '/loop':
179 return loop(environ)
180 else:
181 return [b'Test message']
182
183 # Run the test WSGI server in a separate thread in order not to
184 # interfere with event handling in the main thread
185 server_class = server_ssl_cls if use_ssl else server_cls
186 httpd = server_class(address, SilentWSGIRequestHandler)
187 httpd.set_app(app)
188 httpd.address = httpd.server_address
189 server_thread = threading.Thread(
190 target=lambda: httpd.serve_forever(poll_interval=0.05))
191 server_thread.start()
192 try:
193 yield httpd
194 finally:
195 httpd.shutdown()
196 httpd.server_close()
197 server_thread.join()
198
199
200if hasattr(socket, 'AF_UNIX'):

Callers 2

run_test_unix_serverFunction · 0.85
run_test_serverFunction · 0.85

Calls 6

startMethod · 0.95
joinMethod · 0.95
set_appMethod · 0.80
serve_foreverMethod · 0.45
shutdownMethod · 0.45
server_closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…