Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的正常运行时间功能不是';我不能在Heroku上超过24小时_Python_Python 3.x_Heroku_Discord.py - Fatal编程技术网

Python 我的正常运行时间功能不是';我不能在Heroku上超过24小时

Python 我的正常运行时间功能不是';我不能在Heroku上超过24小时,python,python-3.x,heroku,discord.py,Python,Python 3.x,Heroku,Discord.py,我为Python Discord bot提供了以下正常运行时间函数: import datetime start_time = datetime.datetime.utcnow() # Timestamp of when it came online @client.command(pass_context=True) async def uptime(ctx: commands.Context): now = datetime.datetime.utcnow() # Timesta

我为Python Discord bot提供了以下正常运行时间函数:

import datetime

start_time = datetime.datetime.utcnow() # Timestamp of when it came online

@client.command(pass_context=True)
async def uptime(ctx: commands.Context):
    now = datetime.datetime.utcnow() # Timestamp of when uptime function is run
    delta = now - start_time
    hours, remainder = divmod(int(delta.total_seconds()), 3600)
    minutes, seconds = divmod(remainder, 60)
    days, hours = divmod(hours, 24)
    if days:
        time_format = "**{d}** days, **{h}** hours, **{m}** minutes, and **{s}** seconds."
    else:
        time_format = "**{h}** hours, **{m}** minutes, and **{s}** seconds."
    uptime_stamp = time_format.format(d=days, h=hours, m=minutes, s=seconds)
    await client.say("{} has been up for {}".format(client.user.name, uptime_stamp))
我将此bot部署到Heroku(免费层),几天之后,我发现自己从未获得24小时或更长的正常运行时间(即正常运行时间没有报告天数,似乎在某个地方中途重置,即使bot始终在线)。我想我的函数可能有问题,所以我添加了打印语句来调试,并提供了一个示例开始时间

我的输出表明,该函数能够处理大于1天的差异:

The start time is: 2018-09-02 00:00:00
The time now is: 2018-09-03 18:58:03.458852
The delta is 1 day, 18:58:03.458852
The time difference in seconds is: 154683
Hours: 42, remainder: 3483 seconds
Minutes: 58, remainder: 3 seconds
Days: 1, remainder: 18 hours
The time difference is over one day.
**1** days, **18** hours, **58** minutes, and **3** seconds
>>> 
两个问题:

1) 我的正常运行时间功能正常吗?2)我现在读到Heroku可能每24小时重置一次他们的免费dynos——如果是这样的话,我怎么能得到一个正常运行时间功能,它实际上可以工作几天


谢谢

Heroku每24小时重新启动一次dyno,这样您的正常运行时间就不会超过24小时。您必须将数据保存在Redis之类的存储中,这样它才能跨越重启时间。

Heroku每24小时重启一次dyno,这样您的正常运行时间就不会超过24小时。您必须在Redis这样的存储中持久化数据,以便它跨越重启