Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 gmtime()在armhf平台上导致溢出错误_Python_Datetime_Cherrypy - Fatal编程技术网

Python gmtime()在armhf平台上导致溢出错误

Python gmtime()在armhf平台上导致溢出错误,python,datetime,cherrypy,Python,Datetime,Cherrypy,我有一个Web服务器(CherryPy)在Cubox(armhf平台)上运行,在启动wever时,我得到以下错误: [14/Aug/2015:09:33:40] HTTP Traceback (most recent call last): File "(...)/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 661, in respond self.hooks.run('before_request_body')

我有一个Web服务器(CherryPy)在Cubox(armhf平台)上运行,在启动wever时,我得到以下错误:

[14/Aug/2015:09:33:40] HTTP Traceback (most recent call last):
  File "(...)/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 661, in respond
    self.hooks.run('before_request_body')
  File "(...)/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 114, in run
    raise exc
  File "(...)/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 104, in run
    hook()
  File "(...)/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 63, in __call__
    return self.callback(**self.kwargs)
  File "(...)/lib/python3.4/site-packages/cherrypy/lib/sessions.py", line 901, in init
    httponly=httponly)
  File "(...)/lib/python3.4/site-packages/cherrypy/lib/sessions.py", line 951, in set_response_cookie
    cookie[name]['expires'] = httputil.HTTPDate(e)
  File "(...)/lib/python3.4/site-packages/cherrypy/_cpcompat.py", line 278, in HTTPDate
    return formatdate(timeval, usegmt=True)
  File "/usr/lib/python3.4/email/utils.py", line 177, in formatdate
    now = time.gmtime(timeval)
OverflowError: timestamp out of range for platform time_t
我不确定我是否正确理解这个问题,也不确定我是否能解决它。据我追溯,这是由CherryPy引起的。此错误导致
500内部服务器错误
,无法加载页面

如评论中所问,我插入了一份打印件。我没看到什么特别的东西。这是启动服务器并尝试加载页面后的输出:

1439551125.1483066
1439551132.639804
4593151132.6458025
1439551132.723468
1439551132.7210276
1439551132.7268708
1439551132.7359934
1439551132.741787
1439551132.7452564
4593151132.750907
4593151132.762612
4593151132.749376
4593151132.731232
4593151132.754474
4593151132.763546
1439551132.8183882
4593151132.828029
1439551132.8379567
4593151132.856025
1439551132.8734775
1439551132.8554301
1439551132.879614
4593151132.884698
4593151132.890394
1439551132.8971672
4593151132.902081
4593151132.908171
1439551132.931757
4593151132.944052
1439551132.9759347
1439551132.9714596
4593151132.987068
4593151132.985899
1439551132.9926524
1439551133.0088623
4593151133.013047
1439551133.0280995
4593151133.040709
4593151133.029601
1439551133.0500746
4593151133.057341
1439551133.0749385
4593151133.081711
1439551133.1032782
4593151133.115171
1439551133.1194305
1439551133.1354048
4593151133.143136
4593151133.151044
1439551133.1612003
4593151133.16934
1439551133.1827784
4593151133.19687
1439551133.201899
4593151133.209947
1439551133.271833
4593151133.277573
1439551133.3090906
4593151133.312978
1439551133.3408027
4593151133.344741
1439551133.3722978
4593151133.376283
1439551133.4031894
4593151133.407124
1439551133.434834
4593151133.439074
我不确定这些值中的哪一个会导致错误。我猜是前面有4个?在windows计算机上
time.gmtime(4593151133.439074)
返回包含2115年的结构

启动python shell并输入
time.gmtime(4593151133.439074)
时,我可以在Cubox上重现错误。但我不知道这些价值观从何而来

编辑

我在CherryPy中找到了文件和行,它返回我导致2115年的浮点数。它是文件session.py中的第949-951行:

if timeout:
    e = time.time() + (timeout * 60)
    cookie[name]['expires'] = httputil.HTTPDate(e)

我不知道为什么会有这么高的超时时间。

我发现了这个问题。一位同事将超时设置为一个非常高的超时值,这在32/64位体系结构的Linux或Windows上不会导致任何问题,但在armhf上不会

我可以通过将超时设置为一个较低的值来解决这个问题

cherrypy.request.config.update({'tools.sessions.timeout': 60}) 

要解决armhf平台上C
gmtime()
的范围限制,可以使用显式公式从POSIX时间戳中获取UTC时间:


您是否正确设置了系统时间?@muddyfish我正在Debian上运行服务器,
date
的输出是
Fri Aug 14 09:54:41 CEST 2015
。那么我猜系统时间是正确的?在您的平台上,它也可能是Python错误。你能把
print(timeval)
放在第177行上看看是什么值导致了溢出吗?@saaj我已经编辑了我的问题。
python-m trace--trace script.py
如果armhf是官方支持的python平台,我想在Pyton bugtracker中打开一个问题是有意义的。我既看不到限制,也看不到有关秒数的通知。@saaj:请查阅
man 3 gmtime
以了解范围限制。或
>>> from datetime import datetime, timedelta
>>> datetime(1970, 1, 1) + timedelta(seconds=4593151133.439074)
datetime.datetime(2115, 7, 21, 11, 18, 53, 439074)
>>> datetime.utcfromtimestamp(4593151133.439074) # calls gmtime() internally
datetime.datetime(2115, 7, 21, 11, 18, 53, 439073) # almost same result on non-"right" timezones