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

Fix thread blocking in _invoke_callback() (βœ“ Sandbox Passed) #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions broadcast_service/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ def _invoke_callback(
) -> 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()
def handle_future(future):
try:
result = future.result()
if result is not None:
logger.debug(f"[broadcast-service invoke_callback result] {result}")
return result
except Exception as e:
logger.error(f"[broadcast-service invoke_callback error] {str(e)}")
future_result.add_done_callback(handle_future)
else:
return callback(*args, **kwargs)

Expand Down