Add more robust connectivity checking.

This commit is contained in:
Shiz 2014-01-30 09:00:57 +01:00
parent c22cc437df
commit 89bcc077d5
1 changed files with 6 additions and 0 deletions

View File

@ -194,6 +194,9 @@ class Connection:
def has_message(self, types=None): def has_message(self, types=None):
""" Determine if this connection has a message ready for processing. """ """ Determine if this connection has a message ready for processing. """
if not self.connected:
return False
# Low-hanging fruit: is there a message ready in the queue? # Low-hanging fruit: is there a message ready in the queue?
if len(self.message_queue) > 0: if len(self.message_queue) > 0:
# Is the message of the type we want? # Is the message of the type we want?
@ -221,6 +224,9 @@ class Connection:
def get_message(self, types=None, retry=False): def get_message(self, types=None, retry=False):
""" Get an IRC message for processing. """ """ Get an IRC message for processing. """
if not self.connected:
raise NotConnected('Not connected.')
with self.message_lock: with self.message_lock:
try: try:
# Looking for specific type? # Looking for specific type?