def poll(self, timeout):
now = time.time()<EOL>end_time = now + float(timeout)<EOL>prev_timeout = self.stream.gettimeout()<EOL>self.stream.settimeout(self._poll_period)<EOL>incoming = None<EOL>try:<EOL><INDENT>while (end_time - now) >= <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>incoming = self.stream.recv(self._max_read)<EOL><DEDENT>except socket.timeout:<EOL><INDENT>pass<EOL><DEDENT>if incoming:<EOL><INDENT>return incoming<EOL><DEDENT>now = time.time()<EOL><DEDENT>raise ExpectTimeout()<EOL><DEDENT>finally:<EOL><INDENT>self.stream.settimeout(prev_timeout)<EOL><DEDENT>
:param float timeout: Timeout in seconds. A timeout that is less than
    the poll_period will still cause a single read that may take up to
    poll_period seconds.