MCPcopy Index your code
hub / github.com/plotly/dash / start

Method start

dash/testing/application_runners.py:158–218  ·  view source on GitHub ↗

Start the app server in threading flavor.

(self, app, start_timeout=3, **kwargs)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

stopMethod · 0.95
DashAppLoadingErrorClass · 0.90
KillerThreadClass · 0.85
killMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected