Skip to content
Snippets Groups Projects
Commit a6662582 authored by Eric S. Raymond's avatar Eric S. Raymond
Browse files

Deal with exceptions in a more civilized way.

parent d9a57aad
Branches
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ except ImportError:
CONNECTION_MAX = 200
green_threads = False
import sys, getopt, urlparse, time, random
import sys, getopt, urlparse, time, random, exceptions
import threading, Queue, SocketServer
import irc.client, logging
try:
......@@ -110,7 +110,7 @@ class Connection:
self.port = port
self.nick_trial = None
self.connection = None
self.status = "unseen"
self.status = None
self.last_xmit = time.time()
self.last_ping = time.time()
self.channels_joined = []
......@@ -159,12 +159,14 @@ class Connection:
def enqueue(self, channel, message):
"Enque a message for transmission."
if self.thread is None or not self.thread.is_alive():
self.status = "unseen"
self.thread = threading.Thread(target=self.dequeue)
self.thread.setDaemon(True)
self.thread.start()
self.queue.put((channel, message))
def dequeue(self):
"Try to ship pending messages from the queue."
try:
while True:
# We want to be kind to the IRC servers and not hold unused
# sockets open forever, so they have a time-to-live. The
......@@ -241,6 +243,10 @@ class Connection:
self.last_xmit = time.time()
self.irker.debug(1, "XMIT_TTL bump (%s transmission) at %s" % (self.servername, time.asctime()))
self.queue.task_done()
except:
(exc_type, exc_value, exc_traceback) = sys.exc_info()
self.logerr("exception %s in thread for %s" % \
(exc_type, self.servername))
def live(self):
"Should this connection not be scavenged?"
return self.status != "expired"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment