Start the app server in threading flavor.
(self, app, start_timeout=3, **kwargs)
| 156 | |
| 157 | # pylint: disable=arguments-differ |
| 158 | def start(self, app, start_timeout=3, **kwargs): |
| 159 | """Start the app server in threading flavor.""" |
| 160 | self._app = app # Store app reference for graceful shutdown |
| 161 | |
| 162 | def run(): |
| 163 | app.scripts.config.serve_locally = True |
| 164 | app.css.config.serve_locally = True |
| 165 | |
| 166 | options = kwargs.copy() |
| 167 | options["dev_tools_disable_version_check"] = True |
| 168 | |
| 169 | if "port" not in kwargs: |
| 170 | options["port"] = self.port = BaseDashRunner._next_port |
| 171 | BaseDashRunner._next_port += 1 |
| 172 | else: |
| 173 | self.port = options["port"] |
| 174 | |
| 175 | try: |
| 176 | module = app.server.__class__.__module__ |
| 177 | # FastAPI support |
| 178 | if module.startswith("fastapi"): |
| 179 | app.run(**options) |
| 180 | # Quart support (ASGI - runs its own async event loop) |
| 181 | elif module.startswith("quart"): |
| 182 | app.run(**options) |
| 183 | # Flask fallback (WSGI - needs threaded mode) |
| 184 | else: |
| 185 | app.run(threaded=True, **options) |
| 186 | except SystemExit: |
| 187 | logger.info("Server stopped") |
| 188 | except Exception as error: |
| 189 | logger.exception(error) |
| 190 | raise error |
| 191 | |
| 192 | retries = 0 |
| 193 | |
| 194 | while not self.started and retries < 3: |
| 195 | try: |
| 196 | if self.thread: |
| 197 | if self.thread.is_alive(): |
| 198 | self.stop() |
| 199 | else: |
| 200 | self.thread.kill() |
| 201 | |
| 202 | self.thread = KillerThread(target=run) |
| 203 | self.thread.daemon = True |
| 204 | self.thread.start() |
| 205 | # wait until server is able to answer http request |
| 206 | wait.until( |
| 207 | lambda: self.running_and_accessible(self.url), timeout=start_timeout |
| 208 | ) |
| 209 | self.started = self.thread.is_alive() |
| 210 | except Exception as err: # pylint: disable=broad-except |
| 211 | logger.exception(err) |
| 212 | self.started = False |
| 213 | retries += 1 |
| 214 | time.sleep(1) |
| 215 |
nothing calls this directly
no test coverage detected