How do I make a Python plug-in for Hexchat thread-safe?

208
December 19, 2019, at 00:50 AM

I tried to write a simple Python plug-in for the Hexchat IRC client. However, it seems it is not thread-safe and causes that Hexchat crashes.

__module_name__ = "Demo"
__module_version__ = "1.0"
__module_description__ = "Demo plug-in"
import hexchat
from threading import Thread
from time import sleep
def sleep10seconds():
    hexchat.prnt("before sleep")
    sleep(10)
    hexchat.prnt("sleep end")
    hexchat.command("server " + hexchat.get_info("host"))
    return
# This function is called when a "disconnected" print event was found
def disconnected_cb(word, word_eol, userdata):
    # The sleep() needs to run in a separate thread. Otherwise, the UI
    # freezes for the time of the sleep()
    myThread = Thread(target=sleep10seconds)
    myThread.start()
    return hexchat.EAT_NONE
hexchat.command("discon")
hexchat.command("server " + hexchat.get_info("host"))
hexchat.hook_print("Disconnected", disconnected_cb)

I read some articles about thread safety, but I'm not a developer. I couldn't figure out what I need to change. Can you please help me? Thanks.

Rent Charter Buses Company
READ ALSO
Make only one checkbox selected at the moment and getting the error [closed]

Make only one checkbox selected at the moment and getting the error [closed]

Want to improve this question? Update the question so it's on-topic for Stack Overflow

177
Making an entrie application go through proxy

Making an entrie application go through proxy

so I'm trying to create an app like Proxifier which lets you choose what application you want to run through proxyI tried PySocks but it seems it is only capable to connect to websites

153
Error converting a 3 tiered nested list to ndim numpy array

Error converting a 3 tiered nested list to ndim numpy array

I have already gone through similar questions on the forum, but did not find anyone solving my query

164
MatPlotLib create labels in the legend from the df

MatPlotLib create labels in the legend from the df

I have created multipleline plot that shows data about different plantsRight now the legend is based on index of numbers that was creates as defult

149