-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Error in total time consumption statistics for executing records #4459
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| @date:2025/11/13 19:02 | ||
| @desc: | ||
| """ | ||
| import time | ||
| import traceback | ||
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
||
|
|
@@ -43,6 +44,7 @@ def get_start_node(self): | |
| return start_node_list[0] | ||
|
|
||
| def run(self): | ||
| self.context['start_time'] = time.time() | ||
| executor.submit(self._run) | ||
|
|
||
| def _run(self): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code looks mostly clean and follows Python best practices. However, there are a few areas that could be improved:
Here's a revised version of the method assuming proper usage conventions: def run(self):
# Initialize execution time
self.context['start_time'] = time.time()
# Submit initial task
future = executor.submit(self._run)
try:
# Wait until all futures complete
future.result(timeout=None)
except Exception as e:
print(f"An error occurred: {e}")This change ensures that the initialization step and subsequent submission of tasks work together seamlessly without any logical inconsistencies. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has several irregularities and potential optimizations:
Inconsistent Use of
forLoop: In the constructor (__init__) andhandler, there are different use cases for loops (if ... else ifvs. list comprehension). This can be inconsistent and lead to bugs.Potential Null Value: The line at the end of the
handlermethod usesworkflow.context.get('start_time'), which could potentially returnNone. Using0when it's missing doesn't align with common practice (e.g., handling null values).Useless List Comprehension: The list comprehension
[True for key, value in workflow.get_runtime_details().items() if value.get('status') == 500]creates a list without using its elements. It would be more efficient to just calculate the error flag directly without storing all individual True/False results.Redundant Time Calculation: Calculating
time.time() - workflow.context.get('start_time')twice within an assignment statement is redundant. Only calculate it once if needed multiple times or store in variable first.Optimized version:
Additional notes:
models.Model), ensure all referenced classes (KnowledgeAction,State). If these are custom classes elsewhere, adjust accordingly.state.