Tuesday, 13 November 2018

Threads persisting with irc.bot.SingleServerIRCBot (using with twitch)

What is the correct way to send a disconnect signal to a thread containing a SingleServerIRCBot?

I am instantiating the bots with

import threading
import irc.bot
class MyBot(irc.bot.SingleServerIRCBot):
    ...
bot = MyBot(...)
threads = []
t = threading.Thread(target=bot.start()
threads.append(t)
t.start()

When the stream no longer exists, no matter what I've tried, I haven't been able to get the thread to successfully end. How should I go about sending a signal to the thread that tells it to exit the channel kill the bot and then itself?

The code for the .start method can be found here https://github.com/jaraco/irc/blob/master/irc/bot.py#L331

My first thought is to override that method with a while loop that has an exit condition. I haven't had any luck with that so far though.

Furthermore, there is a .die method here https://github.com/jaraco/irc/blob/master/irc/bot.py#L269 but how can I call that method when the thread is executing an infinite loop?

Trying to kill the threads directly ends up with them persisting, and eventually throwing errors about the total number of threads that my process is running.



from Threads persisting with irc.bot.SingleServerIRCBot (using with twitch)

No comments:

Post a Comment