MCPcopy Index your code
hub / github.com/reactive-python/reactpy / serve_development_app

Function serve_development_app

src/py/reactpy/reactpy/backend/flask.py:93–130  ·  view source on GitHub ↗

Run a development server for FastAPI

(
    app: Flask,
    host: str,
    port: int,
    started: asyncio.Event | None = None,
)

Source from the content-addressed store, hash-verified

91
92# BackendType.serve_development_app
93async def serve_development_app(
94 app: Flask,
95 host: str,
96 port: int,
97 started: asyncio.Event | None = None,
98) -> None:
99 """Run a development server for FastAPI"""
100 loop = asyncio.get_running_loop()
101 stopped = asyncio.Event()
102
103 server: Ref[BaseWSGIServer] = Ref()
104
105 def run_server() -> None:
106 server.current = make_server(host, port, app, threaded=True)
107 if started:
108 loop.call_soon_threadsafe(started.set)
109 try:
110 server.current.serve_forever() # type: ignore
111 finally:
112 loop.call_soon_threadsafe(stopped.set)
113
114 thread = Thread(target=run_server, daemon=True)
115 thread.start()
116
117 if started:
118 await started.wait()
119
120 try:
121 await stopped.wait()
122 finally:
123 # we may have exited because this task was cancelled
124 server.current.shutdown()
125 # the thread should eventually join
126 thread.join(timeout=3)
127 # just double check it happened
128 if thread.is_alive(): # nocov
129 msg = "Failed to shutdown server."
130 raise RuntimeError(msg)
131
132
133def use_websocket() -> WebSocket:

Callers

nothing calls this directly

Calls 2

waitMethod · 0.95
RefClass · 0.90

Tested by

no test coverage detected