MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / start_server

Function start_server

pywebio/platform/aiohttp.py:172–222  ·  view source on GitHub ↗

Start a aiohttp server to provide the PyWebIO application as a web service. :param dict websocket_settings: The parameters passed to the constructor of ``aiohttp.web.WebSocketResponse``. For details, please refer: https://docs.aiohttp.org/en/stable/web_reference.html#websocketresponse

(applications, port=0, host='', debug=False,
                 cdn=True, static_dir=None, remote_access=False,
                 reconnect_timeout=0,
                 allowed_origins=None, check_origin=None,
                 auto_open_webbrowser=False,
                 max_payload_size='200M',
                 websocket_settings=None,
                 **aiohttp_settings)

Source from the content-addressed store, hash-verified

170
171
172def start_server(applications, port=0, host='', debug=False,
173 cdn=True, static_dir=None, remote_access=False,
174 reconnect_timeout=0,
175 allowed_origins=None, check_origin=None,
176 auto_open_webbrowser=False,
177 max_payload_size='200M',
178 websocket_settings=None,
179 **aiohttp_settings):
180 """Start a aiohttp server to provide the PyWebIO application as a web service.
181
182
183 :param dict websocket_settings: The parameters passed to the constructor of ``aiohttp.web.WebSocketResponse``.
184 For details, please refer: https://docs.aiohttp.org/en/stable/web_reference.html#websocketresponse
185 :param aiohttp_settings: Additional keyword arguments passed to the constructor of ``aiohttp.web.Application``.
186 For details, please refer: https://docs.aiohttp.org/en/stable/web_reference.html#application
187
188 The rest arguments of ``start_server()`` have the same meaning as for :func:`pywebio.platform.tornado.start_server`
189 """
190 kwargs = locals()
191
192 if not host:
193 host = '0.0.0.0'
194
195 if port == 0:
196 port = get_free_port()
197
198 cdn = cdn_validation(cdn, 'warn')
199
200 handler = webio_handler(applications, cdn=cdn, allowed_origins=allowed_origins, reconnect_timeout=reconnect_timeout,
201 check_origin=check_origin, max_payload_size=max_payload_size,
202 websocket_settings=websocket_settings)
203
204 app = web.Application(**aiohttp_settings)
205 app.router.add_routes([web.get('/', handler)])
206 if static_dir is not None:
207 app.router.add_routes([web.static('/static', static_dir)])
208 app.router.add_routes(static_routes())
209
210 if auto_open_webbrowser:
211 asyncio.get_event_loop().create_task(open_webbrowser_on_server_started('127.0.0.1', port))
212
213 debug = Session.debug = os.environ.get('PYWEBIO_DEBUG', debug)
214 if debug:
215 logging.getLogger("asyncio").setLevel(logging.DEBUG)
216
217 print_listen_address(host, port)
218
219 if remote_access:
220 start_remote_access_service(local_port=port)
221
222 web.run_app(app, host=host, port=port)

Callers 1

start_test_serverFunction · 0.90

Calls 8

get_free_portFunction · 0.85
cdn_validationFunction · 0.85
static_routesFunction · 0.85
print_listen_addressFunction · 0.85
webio_handlerFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…