Discordbot using threading raise "RuntimeError: set_wakeup_fd only works in main thread" only on linux

Discordbot using threading raise "RuntimeError: set_wakeup_fd only works in main thread" only on linux

我正在使用线程模块同时托管网络服务器和 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)

我建议您在异步协程中使用 client.start() 而不是在单独的线程中使用 client.run()

更详细的例子

webserver.start()
dcbot.run()

好的,现在它启动了网络服务器和机器人。但是当我在机器人启动后尝试做某事时,什么也没有发生。但是,我对为什么会这样很感兴趣。如果有人知道关于线程的书籍之类的好的和广泛的贡献,请发送它