| 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 | |