Home / Function/ ensure_sync() — flask Function Reference

ensure_sync() — flask Function Reference

Architecture documentation for the ensure_sync() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  a89c0022_4807_bf16_9be1_6a66f3c78c9f["ensure_sync()"]
  9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"]
  a89c0022_4807_bf16_9be1_6a66f3c78c9f -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5
  8c4a599b_81bd_7179_af9c_5ae61d56dc9d["update_template_context()"]
  8c4a599b_81bd_7179_af9c_5ae61d56dc9d -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  8f350fa4_a679_30fa_08ca_b4da93c5698c["handle_http_exception()"]
  8f350fa4_a679_30fa_08ca_b4da93c5698c -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  0b9edff8_7a0a_5286_0e0e_b7d04e6a35e6["handle_user_exception()"]
  0b9edff8_7a0a_5286_0e0e_b7d04e6a35e6 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  738c25cf_2aef_f422_7e87_9520ea64ce07["handle_exception()"]
  738c25cf_2aef_f422_7e87_9520ea64ce07 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  59b4fb78_3cac_a043_29b8_6e0b8103b575["dispatch_request()"]
  59b4fb78_3cac_a043_29b8_6e0b8103b575 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  cd857c6c_da43_da88_26ed_c88b074b880a["preprocess_request()"]
  cd857c6c_da43_da88_26ed_c88b074b880a -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  f653c3a8_c501_85ce_5865_f14ec4664394["process_response()"]
  f653c3a8_c501_85ce_5865_f14ec4664394 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  4d256419_1a27_7374_504e_d3f347cc6327["do_teardown_request()"]
  4d256419_1a27_7374_504e_d3f347cc6327 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  8cfcdfb0_4dd6_88ca_6e35_c201392db60e["do_teardown_appcontext()"]
  8cfcdfb0_4dd6_88ca_6e35_c201392db60e -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  f7f0b202_038e_4088_d0b8_b9f6511ffba0["copy_current_request_context()"]
  f7f0b202_038e_4088_d0b8_b9f6511ffba0 -->|calls| a89c0022_4807_bf16_9be1_6a66f3c78c9f
  932db8de_227d_6d62_8474_b93b49f1ed96["async_to_sync()"]
  a89c0022_4807_bf16_9be1_6a66f3c78c9f -->|calls| 932db8de_227d_6d62_8474_b93b49f1ed96
  style a89c0022_4807_bf16_9be1_6a66f3c78c9f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/app.py lines 1064–1076

    def ensure_sync(self, func: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
        """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
        """
        if iscoroutinefunction(func):
            return self.async_to_sync(func)

        return func

Subdomains

Defined In

Frequently Asked Questions

What does ensure_sync() do?
ensure_sync() is a function in the flask codebase, defined in src/flask/app.py.
Where is ensure_sync() defined?
ensure_sync() is defined in src/flask/app.py at line 1064.
What does ensure_sync() call?
ensure_sync() calls 1 function(s): async_to_sync.
What calls ensure_sync()?
ensure_sync() is called by 10 function(s): copy_current_request_context, dispatch_request, do_teardown_appcontext, do_teardown_request, handle_exception, handle_http_exception, handle_user_exception, preprocess_request, and 2 more.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free