Start a Tornado server to provide the PyWebIO application as a web service. The Tornado server communicates with the browser by WebSocket protocol. Tornado is the default backend server for PyWebIO applications, and ``start_server`` can be imported directly using ``from pywebio import
(applications: Union[Callable[[], None], List[Callable[[], None]], Dict[str, Callable[[], None]]],
port: int = 0, host: str = '', debug: bool = False, cdn: Union[bool, str] = True,
static_dir: Optional[str] = None, remote_access: bool = False, reconnect_timeout: int = 0,
allowed_origins: Optional[List[str]] = None, check_origin: Callable[[str], bool] = None,
auto_open_webbrowser: bool = False, max_payload_size: Union[int, str] = '200M',
**tornado_app_settings)
| 208 | |
| 209 | |
| 210 | def start_server(applications: Union[Callable[[], None], List[Callable[[], None]], Dict[str, Callable[[], None]]], |
| 211 | port: int = 0, host: str = '', debug: bool = False, cdn: Union[bool, str] = True, |
| 212 | static_dir: Optional[str] = None, remote_access: bool = False, reconnect_timeout: int = 0, |
| 213 | allowed_origins: Optional[List[str]] = None, check_origin: Callable[[str], bool] = None, |
| 214 | auto_open_webbrowser: bool = False, max_payload_size: Union[int, str] = '200M', |
| 215 | **tornado_app_settings): |
| 216 | """Start a Tornado server to provide the PyWebIO application as a web service. |
| 217 | |
| 218 | The Tornado server communicates with the browser by WebSocket protocol. |
| 219 | |
| 220 | Tornado is the default backend server for PyWebIO applications, |
| 221 | and ``start_server`` can be imported directly using ``from pywebio import start_server``. |
| 222 | |
| 223 | :param list/dict/callable applications: PyWebIO application. |
| 224 | Can be a task function, a list of functions, or a dictionary. |
| 225 | Refer to :ref:`Advanced topic: Multiple applications in start_server() <multiple_app>` for more information. |
| 226 | |
| 227 | When the task function is a coroutine function, use :ref:`Coroutine-based session <coroutine_based_session>` implementation, |
| 228 | otherwise, use thread-based session implementation. |
| 229 | :param int port: The port the server listens on. |
| 230 | When set to ``0``, the server will automatically select a available port. |
| 231 | :param str host: The host the server listens on. ``host`` may be either an IP address or hostname. |
| 232 | If it’s a hostname, the server will listen on all IP addresses associated with the name. |
| 233 | ``host`` may be an empty string or None to listen on all available interfaces. |
| 234 | :param bool debug: Tornado Server's debug mode. If enabled, the server will automatically reload for code changes. |
| 235 | See `tornado doc <https://www.tornadoweb.org/en/stable/guide/running.html#debug-mode>`_ for more detail. |
| 236 | :param bool/str cdn: Whether to load front-end static resources from CDN, the default is ``True``. |
| 237 | Can also use a string to directly set the url of PyWebIO static resources. |
| 238 | :param str static_dir: The directory to store the application static files. |
| 239 | The files in this directory can be accessed via ``http://<host>:<port>/static/files``. |
| 240 | For example, if there is a ``A/B.jpg`` file in ``static_dir`` path, |
| 241 | it can be accessed via ``http://<host>:<port>/static/A/B.jpg``. |
| 242 | :param bool remote_access: Whether to enable remote access, when enabled, |
| 243 | you can get a temporary public network access address for the current application, |
| 244 | others can access your application via this address. |
| 245 | :param bool auto_open_webbrowser: Whether or not auto open web browser when server is started (if the operating system allows it) . |
| 246 | :param int reconnect_timeout: The client can reconnect to server within ``reconnect_timeout`` seconds after an unexpected disconnection. |
| 247 | If set to 0 (default), once the client disconnects, the server session will be closed. |
| 248 | :param list allowed_origins: The allowed request source list. (The current server host is always allowed) |
| 249 | The source contains the protocol, domain name, and port part. |
| 250 | Can use Unix shell-style wildcards: |
| 251 | |
| 252 | - ``*`` matches everything |
| 253 | - ``?`` matches any single character |
| 254 | - ``[seq]`` matches any character in *seq* |
| 255 | - ``[!seq]`` matches any character not in *seq* |
| 256 | |
| 257 | Such as: ``https://*.example.com`` 、 ``*://*.example.com`` |
| 258 | |
| 259 | For detail, see `Python Doc <https://docs.python.org/zh-tw/3/library/fnmatch.html>`_ |
| 260 | :param callable check_origin: The validation function for request source. |
| 261 | It receives the source string (which contains protocol, host, and port parts) as parameter and |
| 262 | return ``True/False`` to indicate that the server accepts/rejects the request. |
| 263 | If ``check_origin`` is set, the ``allowed_origins`` parameter will be ignored. |
| 264 | :param bool auto_open_webbrowser: Whether or not auto open web browser when server is started (if the operating system allows it) . |
| 265 | :param int/str max_payload_size: Max size of a websocket message which Tornado can accept. |
| 266 | Messages larger than the ``max_payload_size`` (default 200MB) will not be accepted. |
| 267 | ``max_payload_size`` can be a integer indicating the number of bytes, or a string ending with `K` / `M` / `G` |
nothing calls this directly
no test coverage detected
searching dependent graphs…