Skip to content

Commit

Permalink
refactor Watchdog class
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed May 24, 2024
1 parent d45ccdc commit 2afecc7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/ezdxf/edgeminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,10 @@ def start(self, timeout: float):
self.timeout = timeout
self.start_time = time.perf_counter()

@property
def has_timed_out(self) -> bool:
return time.perf_counter() - self.start_time > self.timeout

def check_timeout(self, msg: str) -> None:
if self.has_timed_out():
raise TimeoutError(msg)


def length(edges: Sequence[Edge]) -> float:
"""Returns the length of a sequence of edges."""
Expand Down Expand Up @@ -312,8 +309,8 @@ def search(self, start: Edge, available: Sequence[Edge], timeout=TIMEOUT):

def _search(self, loop: Loop, available: tuple[Edge, ...]):
for next_edge in available:
# raises TimeoutError:
self.watchdog.check_timeout("search process has timed out")
if self.watchdog.has_timed_out:
raise TimeoutError("search process has timed out")
edge = next_edge
extended_loop: Loop | None = None
if loop.is_connected(edge, self._gap_tol):
Expand Down Expand Up @@ -459,7 +456,8 @@ def process(vertex: Vec3) -> None:
watchdog = Watchdog(timeout)

while todo:
watchdog.check_timeout("build process has timed out")
if watchdog.has_timed_out:
raise TimeoutError("build process has timed out")
edge = todo.pop()
process(edge.start)
process(edge.end)
Expand Down

0 comments on commit 2afecc7

Please sign in to comment.