mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-07 04:56:54 +00:00
MINOR: Fix 'calculate_execution_time_generator' (#14987)
* Refactor the calculate_execution_time for generators decorator in order to fix it * Add small comment in the code
This commit is contained in:
parent
2eda75b78b
commit
c2bb1e5004
@ -125,12 +125,27 @@ def calculate_execution_time_generator(func):
|
||||
"""
|
||||
|
||||
def calculate_debug_time(*args, **kwargs):
|
||||
start = perf_counter()
|
||||
yield from func(*args, **kwargs)
|
||||
end = perf_counter()
|
||||
logger.debug(
|
||||
f"{func.__name__} executed in { pretty_print_time_duration(end - start)}"
|
||||
)
|
||||
# NOTE: We are basically implementing by hand a simplified version of 'yield from'
|
||||
# in order to be able to calculate the time difference correctly.
|
||||
# The 'while True' loop allows us to guarantee we are iterating over all thje values
|
||||
# from func(*args, **kwargs).
|
||||
generator = func(*args, **kwargs)
|
||||
|
||||
while True:
|
||||
start = perf_counter()
|
||||
|
||||
try:
|
||||
element = next(generator)
|
||||
except StopIteration:
|
||||
return
|
||||
|
||||
end = perf_counter()
|
||||
|
||||
logger.debug(
|
||||
f"{func.__name__} executed in { pretty_print_time_duration(end - start)}"
|
||||
)
|
||||
|
||||
yield element
|
||||
|
||||
return calculate_debug_time
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user