Skip to content

does async callback supported? #41

Open

Description

@congzhangzh

like title!

Activity

  1. AlbertShown commented on Sep 26, 2025

    @AlbertShown
    Member

    WebUI supports it, it's implemented by default in some wrappers like Deno-WebUI because everything is async, but in Python-WebUI I think it should be done manually.

    To make your WebUI project support async try this:

    1 - initialize WebUI with async enabled

    # in your main start, initialize WebUI with async enabled
    # Config.asynchronous_response = number 5
    # More info: 
    # https://github.com/webui-dev/python-webui/blob/c4b55892baa9367dd7cd4005ab30542e81f954b4/PyPI/Package/src/webui/webui.py#L116
    
    set_config(Config.asynchronous_response, True)
    
    # Now, WebUI events will bypass the callback instant return, and wait forever for the async response trough any `e.return_xxx()`

    2 - Set your event async response

    # In your events call, make sure to call any `e.return_xxx()` to set your async response to the UI
    
    def myCallbackExample(e : webui.Event):
          # do your async operations...
          # Python may return right away a void response to C (WebUI), but WebUI will ignore it and wait for any `e.return_xxx()`
          e.return_int(123) # Now WebUI will pass the response to UI.
  2. congzhangzh commented on Sep 26, 2025

    @congzhangzh
    Author

    Tks, Btw how you guys stop asyncio event loop from blocking, as main thread is waiting?

    webui.wait()

    I am the author of https://github.com/congzhangzh/webview_python , to make wait work, I even monkey patch python asyncio, like:

    https://github.com/congzhangzh/webview_python/tree/main/examples/async_with_asyncio_guest_run

  3. congzhangzh commented on Sep 26, 2025

    @congzhangzh
    Author

    use multi thread?

  4. AlbertShown commented on Sep 29, 2025

    @AlbertShown
    Member

    this project structure is different from your project structure because this one calls a C external library, while yours is directly using webview.

    However, code is here:
    https://github.com/webui-dev/python-webui/blob/c4b55892baa9367dd7cd4005ab30542e81f954b4/PyPI/Package/src/webui/webui.py#L1544C5-L1544C22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions