diff --git a/mitogen/parent.py b/mitogen/parent.py index 79b9454d..aaa24041 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -276,6 +276,10 @@ class Stream(mitogen.core.Stream): #: Maximum time to wait for a connection attempt. connect_timeout = 30.0 + #: Derived from :py:attr:`connect_timeout`; absolute floating point + #: UNIX timestamp after which the connection attempt should be abandoned. + connect_deadline = None + #: True to cause context to write verbose /tmp/mitogen..log. debug = False @@ -306,6 +310,7 @@ class Stream(mitogen.core.Stream): self.remote_name = remote_name self.debug = debug self.profiling = profiling + self.connect_deadline = time.time() + self.connect_timeout def on_shutdown(self, broker): """Request the slave gracefully shut itself down.""" diff --git a/mitogen/ssh.py b/mitogen/ssh.py index 8a115383..1841d484 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -112,8 +112,12 @@ class Stream(mitogen.parent.Stream): def _connect_bootstrap(self): password_sent = False - for buf in mitogen.parent.iter_read(self.receive_side.fd, - time.time() + 10.0): + it = mitogen.parent.iter_read( + fd=self.receive_side.fd, + deadline=self.connect_deadline + ) + + for buf in it: LOG.debug('%r: received %r', self, buf) if buf.endswith('EC0\n'): self._ec0_received() diff --git a/mitogen/sudo.py b/mitogen/sudo.py index 78aa3063..8e4ab3c3 100644 --- a/mitogen/sudo.py +++ b/mitogen/sudo.py @@ -149,8 +149,13 @@ class Stream(mitogen.parent.Stream): def _connect_bootstrap(self): password_sent = False - for buf in mitogen.parent.iter_read(self.receive_side.fd, - time.time() + 10.0): + it = mitogen.parent.iter_read( + fd=self.receive_side.fd, + deadline=self.connect_deadline, + display_on_failure=0 + ) + + for buf in it: LOG.debug('%r: received %r', self, buf) if buf.endswith('EC0\n'): self._ec0_received()