gpt4 book ai didi

python - Discordbot 仅在 Linux 上使用线程引发 "RuntimeError: set_wakeup_fd only works in main thread"

转载 作者:行者123 更新时间:2023-12-03 09:52:29 24 4
gpt4 key购买 nike

我正在使用线程模块同时托管 Web 服务器和 Discord 机器人。一切在 Windows 上运行良好,但一旦我将它加载到我的 Linux 服务器上,我就会收到以下错误:

Starting Bot
Exception in thread Bot:
Traceback (most recent call last):
File "/usr/lib/python3.8/asyncio/unix_events.py", line 95, in add_signal_handler
signal.set_wakeup_fd(self._csock.fileno())
ValueError: set_wakeup_fd only works in main thread

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/home/webadmin/discordbot/bot/moduls/m_threadingmaker.py", line 15, in run
self.client.run(self.args[0])
File "/home/webadmin/discordbot/bot/venv/lib/python3.8/site-packages/discord/client.py", line 614, in run
loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
File "/usr/lib/python3.8/asyncio/unix_events.py", line 97, in add_signal_handler
raise RuntimeError(str(exc))
RuntimeError: set_wakeup_fd only works in main thread
我已经从 python 3.7 升级到 python 3.8,但我仍然有同样的错误。
这是我的代码:
main.py(网络服务器工作)
dcbot = m_threadingmaker.myThread("Bot", client, secrets.token)
webserver = m_threadingmaker.myThread("Flask", app, 'localhost', '7010')

#webserver.start()
dcbot.start()
M_threadingmaker.py
from threading import Thread

class myThread (Thread):
def __init__(self, name, client, *args):
Thread.__init__(self)
self.name = name
self.client = client
self.args = args

def run(self):
print("Starting " + self.name)
if self.name == "Flask":
self.client.run(host=self.args[0], port=self.args[1])
else:
self.client.run(self.args[0])
print("Exiting " + self.name)

最佳答案

webserver.start()
dcbot.run()
好的,现在它启动了网络服务器和机器人。但是当我在机器人启动后尝试做某事时,什么也没有发生。但是,我对为什么会这样感兴趣。如果有人知道一个好的和广泛的贡献,比如线程方面的书籍,请发送

关于python - Discordbot 仅在 Linux 上使用线程引发 "RuntimeError: set_wakeup_fd only works in main thread",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62671883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com