Преглед на файлове

trying to catch socket errors and restart on them

tags/v0.1
Ben Kurtovic преди 13 години
родител
ревизия
6d35a6964c
променени са 2 файла, в които са добавени 19 реда и са изтрити 5 реда
  1. +10
    -5
      bot.py
  2. +9
    -0
      irc/actions.py

+ 10
- 5
bot.py Целия файл

@@ -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 Целия файл

@@ -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")


Зареждане…
Отказ
Запис