<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def latency(self):
 """ Checks the connection latency. """

        with self.lock:
            self.send('PING %s' % self.server)
            ctime = self._m_time.time()

            msg = self._recv(expected_replies=('PONG',))
            if msg[0] == 'PONG':
                latency = self._m_time.time() - ctime
                return latency