Quellcode durchsuchen

trying to catch socket errors and restart on them

tags/v0.1
Ben Kurtovic vor 13 Jahren
Ursprung
Commit
6d35a6964c
2 geänderte Dateien mit 19 neuen und 5 gelöschten Zeilen
  1. +10
    -5
      bot.py
  2. +9
    -0
      irc/actions.py

+ 10
- 5
bot.py Datei anzeigen

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

## Imports
import socket, string, re
import socket, string, re, time

from config.irc_config import *
from config.secure_config import *
@@ -14,11 +14,16 @@ def main():
read_buffer = str()

while 1:
read_buffer = read_buffer + actions.sock.recv(1024)
temp = string.split(read_buffer, "\n")
read_buffer = temp.pop()
try:
read_buffer = read_buffer + actions.get()
except RuntimeError: # socket broke
time.sleep(60) # sleep for sixty seconds
return # then exit our loop and restart the bot

for line in temp:
lines = string.split(read_buffer, "\n")
read_buffer = lines.pop()

for line in lines:
line = string.split(string.rstrip(line))
data = Data()



+ 9
- 0
irc/actions.py Datei anzeigen

@@ -2,11 +2,20 @@

# Actions/commands to interface with IRC.

import string

class Actions:
def __init__(self, sock):
"""actions/commands to interface with IRC"""
self.sock = sock

def get(self, size = 4096):
"""receive (get) data from the server"""
data = self.sock.recv(4096)
if not data:
raise RuntimeError("socket is dead")
return data

def send(self, msg):
"""send data to the server"""
self.sock.send(msg + "\r\n")


Laden…
Abbrechen
Speichern