MCPcopy
hub / github.com/pallets/flask / ensure_sync

Method ensure_sync

src/flask/app.py:966–978  ·  view source on GitHub ↗

Ensure that the function is synchronous for WSGI workers. Plain ``def`` functions are returned as-is. ``async def`` functions are wrapped to run and wait for the response. Override this method to change how the app runs async views. .. versionadded:: 2.0

(self, func: t.Callable[..., t.Any])

Source from the content-addressed store, hash-verified

964 return rv
965
966 def ensure_sync(self, func: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
967 """Ensure that the function is synchronous for WSGI workers.
968 Plain ``def`` functions are returned as-is. ``async def``
969 functions are wrapped to run and wait for the response.
970
971 Override this method to change how the app runs async views.
972
973 .. versionadded:: 2.0
974 """
975 if iscoroutinefunction(func):
976 return self.async_to_sync(func)
977
978 return func
979
980 def async_to_sync(
981 self, func: t.Callable[..., t.Coroutine[t.Any, t.Any, t.Any]]

Callers 12

handle_http_exceptionMethod · 0.95
handle_user_exceptionMethod · 0.95
handle_exceptionMethod · 0.95
dispatch_requestMethod · 0.95
preprocess_requestMethod · 0.95
process_responseMethod · 0.95
do_teardown_requestMethod · 0.95
wrapperFunction · 0.80
viewMethod · 0.80
dispatch_requestMethod · 0.80

Calls 1

async_to_syncMethod · 0.95

Tested by

no test coverage detected