“错误”;任务已销毁,但它处于挂起状态”;使用异步。(Python 3.4)

“错误”;任务已销毁,但它处于挂起状态”;使用异步。(Python 3.4),python,asynchronous,Python,Asynchronous,我最近使用Discord.py为Discord服务器开发了一个bot,但在使用async时遇到了一些问题。bot运行了一段时间,但过了一段时间,我出现以下错误: Task was destroyed but it is pending! task: <Task pending coro=<my_background_task() running at setup.py:431> wait_for=<Future pending cb=[Task._wakeup()]>

我最近使用Discord.py为Discord服务器开发了一个bot,但在使用async时遇到了一些问题。bot运行了一段时间,但过了一段时间,我出现以下错误:

Task was destroyed but it is pending!
task: <Task pending coro=<my_background_task() running at setup.py:431> wait_for=<Future pending cb=[Task._wakeup()]>>

非常感谢您的帮助。

在对代码进行了一段时间的修补之后,我发现请求被阻塞,因此我将代码改为使用aiohttp,到目前为止没有错误

@client.async_event
def my_background_task():
  yield from client.wait_until_ready()
  channel = discord.Object(id="121156929409122306")
  while not client.is_closed:
    # STARTS EQ BOT #
    r = requests.get('https://api.pushbullet.com/v2/channel-info?tag=pso2')
    query = json.loads(r.text)

    eq = query['recent_pushes'][0]['body']

    with open('last_eq.json', encoding="utf8") as in_f:
      last_eq = json.load(in_f)

    if last_eq['eq'][-1] != eq:
      last_eq['eq'].append(eq)

      with open('last_eq.json', 'w') as out_f:
        json.dump(last_eq, out_f)

      pso2_channel = discord.Object("148846969861701632")
      yield from client.send_message(pso2_channel, '**EQ ALERT:** %s' % eq)

    # STARTS BUMPED BOT #
    try:
      d = feedparser.parse('http://www.bumped.org/psublog/feed')
      articleTitle = d['entries'][0]['title']
      articleLink = d['entries'][0]['link']

      with open('last_article.json', encoding="utf8") as in_f:
          last_article = json.load(in_f)

      if last_article['article'][-1] != articleTitle:
          last_article['article'].append(articleTitle)

          with open('last_article.json', 'w') as out_f:
              json.dump(last_article, out_f)

          pso2_channel = discord.Object("148846969861701632")
          yield from client.send_message(pso2_channel, '**NEW BUMPED ARTICLE:** %s\n%s' % (articleTitle, articleLink))
    except:
      pass

    yield from asyncio.sleep(60) # task runs every 60 seconds

loop = asyncio.get_event_loop()

try:
  loop.create_task(my_background_task())
  loop.run_until_complete(client.login('email', 'password'))
  loop.run_until_complete(client.connect())
except Exception:
  print(Exception)
finally:
  loop.close()