fix: Return the link to the connection pool after the node execution is completed#3919
fix: Return the link to the connection pool after the node execution is completed#3919shaohuzhang1 merged 1 commit intov1from
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| connection.close() | ||
|
|
||
| def run_node_async(self, node): | ||
| future = executor.submit(self.run_node, node) |
There was a problem hiding this comment.
There are no irregularities in the given code snippet. Here are some minor recommendations for improvement:
# Import necessary modules at the beginning to avoid circular imports or potential issues
from functools import reduce
from typing import List, Dict
import django
django.setup() # Optional setup if not done elsewhere
from django.db import close_old_connections
from django.db.models import QuerySet
from django.utils import translationThe changes ensure that Django is properly initialized before being used, which might be important for certain operations depending on your use case.
Additionally, it's generally a good practice to check if connection has been defined before calling its methods. However, since you're closing it immediately after, this check won't apply but could serve as a reminder:
try:
result = self.hand_event_node_result(
current_node,
node_result_future)
except Exception as e:
print(f"An error occurred while processing {current_node}: {e}")
finally:
try:
close_old_connections()
# If using async tasks, make sure to wait for all futures to complete
node_result_future.result()
except Exception as e:
print("Exception during cleanup")
finally:
current_node.node_chunk.end()
# Optionally, check if 'connection' exists before closing in production
if hasattr(connection, 'close'):
connection.close()Make sure that when running these tasks asynchronously, you handle errors appropriately and possibly call .result() on the future to ensure all operations have completed before cleaning up resources.
fix: Return the link to the connection pool after the node execution is completed