我在共享托管中运行python bot它运行正常但是每天几个小时后它会发生1到2次崩溃。那么是什么导致了这个错误以及如何解决这个问题。
RuntimeError: can't start new thread
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f80a690b6d8>
Task exception was never retrieved
future: <Task finished coro=<WebSocketCommonProtocol.run() done, defined at /home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py:428> exception=ConnectionResetError(104, 'Connection reset by peer')>
Traceback (most recent call last):
File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 434, in run
msg = yield from self.read_message()
File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 456, in read_message
frame = yield from self.read_data_frame(max_size=self.max_size)
File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 511, in read_data_frame
frame = yield from self.read_frame(max_size)
File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 546, in read_frame
self.reader.readexactly, is_masked, max_size=max_size)
File "/home/demotry/.local/lib/python3.6/site-packages/websockets/framing.py", line 86, in read_frame
data = yield from reader(2)
File "/home/demotry/.local/lib/python3.6/asyncio/streams.py", line 674, in readexactly
yield from self._wait_for_data('readexactly')
File "/home/demotry/.local/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
yield from self._waiter
File "/home/demotry/.local/lib/python3.6/asyncio/selector_events.py", line 723, in _read_ready
data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.run() running at /home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py:434> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f80a6970f48>()]>>
我添加了我的bot.py脚本代码,如下面的一些命令只有一个bot.py没有其他文件。一切都很好,但一天崩溃2到3次。
token = "This is my Token" # This is what the bot uses to log into Discord.
prefix = "?" # This will be used at the start of commands.
import discord
from discord.ext import commands
from discord.ext.commands import Bot
bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print(discord.__version__)
print('------')
@bot.command(pass_context=True)
async def ping(ctx):
msg = 'Pong {0.author.mention}'.format(ctx.message)
await bot.say(msg)
@bot.command(pass_context=True)
async def hello(ctx):
msg = 'hello... {0.author.mention}'.format(ctx.message)
await bot.say(msg)
bot.run(token)