【问题标题】:pyTelegramBotAPI: bot stops running after about 1 hour on HerokupyTelegramBotAPI:机器人在 Heroku 上大约 1 小时后停止运行
【发布时间】:2020-11-10 22:45:23
【问题描述】:

我找不到解决方案。我在 Heroku 上使用库 pyTelegramBotAPI 在 python 中托管一个电报机器人,我的代码有效,但脚本 stop 从新部署或通过控制台执行新的 1 或 2 小时后运行(或几分钟,我不知道确切的时间)。 问题出在哪里?感谢您的帮助。

Heroku 上的日志示例:

2020-07-15T10:47:40.500384+00:00 app[api]: Starting process with command `python randobot.py` by user ________@gmail.com
2020-07-15T10:47:44.398310+00:00 heroku[run.1085]: State changed from starting to up
2020-07-15T10:47:44.455749+00:00 heroku[run.1085]: Awaiting client
2020-07-15T10:47:44.773283+00:00 heroku[run.1085]: Starting process with command `python\ randobot.py`
2020-07-15T10:47:50.709806+00:00 heroku[run.1085]: Client connection closed. Sending SIGHUP to all processes
2020-07-15T10:47:51.233462+00:00 heroku[run.1085]: Process exited with status 129
2020-07-15T10:47:51.270855+00:00 heroku[run.1085]: State changed from up to complete  

Procfile.:

web: python randobot.py

代码randobot.py

import telebot
import time
import json

bot_token = "____________________________"
bot = telebot.TeleBot(token=bot_token)

...
... Some functions ...
...

while True: 
    try:
        bot.polling(none_stop=True)

    except Exception as e:
        logger.error(e)
        time.sleep(15)

使用 git 在 Heroku 上进行部署的命令:

git add .
git commit -m "..."
git push heroku master

第一次在 Heroku 上使用命令来运行机器人(在登录 ecc 之后):

heroku ps:scale web=1

【问题讨论】:

    标签: python heroku bots telegram py-telegram-bot-api


    【解决方案1】:

    它可以工作,使用(控制台上的命令):

    heroku ps:scale worker=1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2021-04-17
      • 2021-06-13
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多