ayust / kitnirc

Python IRC bot framework.
MIT License
11 stars 7 forks source link

Handle disconnection. Reconnect? #15

Closed flexd closed 10 years ago

flexd commented 10 years ago
Traceback (most recent call last):
  File "main.py", line 113, in <module>
    main()
  File "main.py", line 107, in main
    client.run()
  File "/home/kristoffer/.virtualenvs/yamcbot/src/kitnirc/kitnirc/client.py", line 299, in run
    self._buffer += self.socket.recv(4096)
socket.error: [Errno 104] Connection reset by peer
ayust commented 10 years ago

KitnIRC's approach to disconnection is to explicitly not handle reconnection, but instead guarantee that the program exits if it disconnects (assuming you're using the healthcheck plugin). Thus you can have the bot reconnect by using a daemon that restarts processes if they exit, or just run it in a shell loop:

while true; do python yourbot.py; sleep 5; done

The reason for this is that it simplifies the state model significantly - there's zero chance of running into issues where state from the previous connection sticks around, not matching the IRC server's impression of the client on the network.