Skip to content

NTP datetime calls hang as no socket timeout is specified #21

Closed
@mattura

Description

@mattura

My code frequently hangs during the ntp call (eg if the connection is lost)
Passing a socket timeout through the function could resolve this or at least allow my code to continue after a short delay

eg:

def __init__(
        self,
        socketpool,
        *,
        server: str = "0.adafruit.pool.ntp.org",
        port: int = 123,
        tz_offset: int = 0,
        socket_timeout = 10
    ) -> None:
   ...
   self._socket_timeout = socket_timeout
   ...

def datetime(self) -> time.struct_time:
...
with self._pool.socket(self._pool.AF_INET, self._pool.SOCK_DGRAM) as sock:
                sock.settimeout(self._socket_timeout)
                sock.sendto(self._packet, (self._server, self._port))
                ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions