Skip to content

Commit

Permalink
review feedback + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
petertdavies authored and SamWilsn committed Jun 21, 2024
1 parent d89d881 commit 78d3a9c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/ethereum_spec_tools/evm_tools/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ def do_POST(self) -> None:


class _UnixSocketHttpServer(socketserver.UnixStreamServer):
last_response: Optional[float] = None
last_response: float
shutdown_timeout: int

def __init__(self, *args: Any, shutdown_timeout: int, **kwargs: Any) -> None:
self.shutdown_timeout = shutdown_timeout
self.last_response = time.monotonic()
# Add a 60-second allowance to prevent server from timing out during
# startup
self.last_response = time.monotonic() + 60.0
super().__init__(*args, **kwargs)

def get_request(self) -> Tuple[Any, Any]:
Expand All @@ -85,16 +87,15 @@ def finish_request(
self.last_response = time.monotonic()

def check_timeout(self) -> None:
if self.shutdown_timeout != 0:
while True:
time.sleep(11.0)
now = time.monotonic()
last_response = self.last_response
if last_response is None:
self.last_response = now
elif now - last_response > float(self.shutdown_timeout):
self.shutdown()
break
while self.shutdown_timeout != 0:
time.sleep(11.0)
now = time.monotonic()
last_response = self.last_response
if last_response is None:
self.last_response = now
elif now - last_response > float(self.shutdown_timeout):
self.shutdown()
break


class Daemon:
Expand Down

0 comments on commit 78d3a9c

Please sign in to comment.