avoid polling  when waiting to send ping.

Small patch to avoid polling when waiting to send ping.
I am not sure line 961 (```self.keep_running = False```) is still needed.