It looks like the socket "s" you get from writables is not in message_queues dictionary.
Are you sure it is?
For best practice protect all this dictionary[key] calls with:
Are you sure it is?
For best practice protect all this dictionary[key] calls with:
if key in dictionary: # stuff else: # log/print errorEDIT: I'm also not sure it's wise to use a socket as a dictionary key, though I'm sure it's possible.