Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

线程池阻塞,达不到并发效果 #17

Open
Succee opened this issue Dec 1, 2023 · 2 comments
Open

线程池阻塞,达不到并发效果 #17

Succee opened this issue Dec 1, 2023 · 2 comments

Comments

@Succee
Copy link

Succee commented Dec 1, 2023

在_core.py文件中的_invoke_callback函数使用了future对象的result方法,会引起线程阻塞,从而无法达到异步的效果

@Undertone0809
Copy link
Owner

发现这个问题了,欢迎提出 pr 修改,或者等作者后续更新 v1.2.1 版本,v1.3.2 版本不存在这个问题,如果没有用到 broadcast.config().public(xxx) 相关的函数,可以使用 v1.3.2 的版本。

@kanadeblisst00
Copy link

def _invoke_callback(
        callback: Callable,
        thread_pool: ThreadPoolExecutor,
        enable_async: bool = True,
        *args,
        **kwargs
) -> Any:
    if enable_async:
        future_result = thread_pool.submit(callback, *args, **kwargs)
        if future_result.result() is not None:
            logger.debug(f"[broadcast-service invoke_callback result] {future_result.result()}")
            return future_result.result()
    else:
        return callback(*args, **kwargs)

future_result.result()会阻塞进程,后面调用也没用返回值,这个判断完全可以注释了

Undertone0809 added a commit that referenced this issue Aug 2, 2024
Related to #17

Remove the `future_result.result()` call in the `_invoke_callback` function to avoid thread blocking.

* Modify the `_invoke_callback` function to submit the callback to the thread pool and return immediately.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Undertone0809/broadcast-service/issues/17?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants