9
9
from queue import Queue as ThreadQueue
10
10
from threading import Event as ThreadEvent
11
11
from threading import Thread
12
- from typing import Any , Callable , Dict , NamedTuple , Optional , Union , cast
12
+ from typing import Any , Callable , Dict , NamedTuple , NoReturn , Optional , Union , cast
13
13
14
14
from flask import (
15
15
Blueprint ,
@@ -84,13 +84,12 @@ async def serve_development_app(
84
84
85
85
server : Ref [BaseWSGIServer ] = Ref ()
86
86
87
- def run_server () -> None : # pragma: no cover
88
- # we don't cover this function because coverage doesn't work right in threads
87
+ def run_server () -> None :
89
88
server .current = make_server (host , port , app , threaded = True )
90
89
if started :
91
90
loop .call_soon_threadsafe (started .set )
92
91
try :
93
- server .current .serve_forever ()
92
+ server .current .serve_forever () # type: ignore
94
93
finally :
95
94
loop .call_soon_threadsafe (stopped .set )
96
95
@@ -178,12 +177,8 @@ def model_stream(ws: WebSocket, path: str = "") -> None:
178
177
def send (value : Any ) -> None :
179
178
ws .send (json .dumps (value ))
180
179
181
- def recv () -> Optional [LayoutEvent ]:
182
- event = ws .receive ()
183
- if event is not None :
184
- return LayoutEvent (** json .loads (event ))
185
- else :
186
- return None
180
+ def recv () -> LayoutEvent :
181
+ return LayoutEvent (** json .loads (ws .receive ()))
187
182
188
183
dispatch_in_thread (ws , path , constructor (), send , recv )
189
184
@@ -197,7 +192,7 @@ def dispatch_in_thread(
197
192
component : ComponentType ,
198
193
send : Callable [[Any ], None ],
199
194
recv : Callable [[], Optional [LayoutEvent ]],
200
- ) -> None :
195
+ ) -> NoReturn :
201
196
dispatch_thread_info_created = ThreadEvent ()
202
197
dispatch_thread_info_ref : idom .Ref [Optional [_DispatcherThreadInfo ]] = idom .Ref (None )
203
198
@@ -255,21 +250,14 @@ def run_send() -> None:
255
250
try :
256
251
while True :
257
252
value = recv ()
258
- if value is None :
259
- stop .set ()
260
- break
261
- # BUG: https://github.com/nedbat/coveragepy/issues/1012
262
- # Coverage isn't able to support concurrency coverage for both threading and gevent
263
- dispatch_thread_info .dispatch_loop .call_soon_threadsafe ( # pragma: no cover
253
+ dispatch_thread_info .dispatch_loop .call_soon_threadsafe (
264
254
dispatch_thread_info .async_recv_queue .put_nowait , value
265
255
)
266
256
finally :
267
257
dispatch_thread_info .dispatch_loop .call_soon_threadsafe (
268
258
dispatch_thread_info .dispatch_future .cancel
269
259
)
270
260
271
- return None
272
-
273
261
274
262
@dataclass
275
263
class Connection :
@@ -290,9 +278,3 @@ class _DispatcherThreadInfo(NamedTuple):
290
278
dispatch_future : "asyncio.Future[Any]"
291
279
thread_send_queue : "ThreadQueue[LayoutUpdate]"
292
280
async_recv_queue : "AsyncQueue[LayoutEvent]"
293
-
294
-
295
- def _join_url_paths (* args : str ) -> str :
296
- # urllib.parse.urljoin performs more logic than is needed. Thus we need a util func
297
- # to join paths as if they were POSIX paths.
298
- return "/" .join (map (lambda x : str (x ).rstrip ("/" ), filter (None , args )))
0 commit comments