开发者

OverflowError: normalized days too large to fit in a C int

开发者 https://www.devze.com 2023-02-04 05:33 出处:网络
I am using the following Python code to compute the User+Sys time. t = os.times() usersystime = t[0] + t[1]

I am using the following Python code to compute the User+Sys time.

t = os.times()
usersystime = t[0] + t[1]
usersystime = datetime.timedelta(seconds=usersystime)

However, on an Amazon EC2 m.4xlarge instance, I get the following error occasionally:

OverflowError: normalized days too large to fit in a C int

I have used this Python code fo开发者_如何学Cr over a year with no problem. Now, on this one type of Amazon EC2 instance (which I have never used before), I get this error.

How do I resolve it?


I've found out that some of Python's built-in functions, such as range or xrange, do not support larger integers, probably because they're implemented in C as an optimization. Take a look at this question for an example.

This could be the case for your code. Does t[0] + t[1] fit in an integer? If not, you'll have to either find a way around it (normalize t[0] + t[1]? Depends on what you want to do, and your snippet doesn't make that clear) or implement your own timedelta.

EDIT:

Taking a look at Python's documentation and running your code on my desktop (WinXP 32bit/Python2.7), I see no reason for an integer overflow. However, you mention that this problem occurs occasionally, so it could be the Amazon instance's times() returning some funky values (yay virtualization ;)).

First, try doing some tests to determine for exactly what ranges of t[0] and t[1] the exception happens. If they actually do have some uncommonly high values (maybe because the instance was paused then resumed, don't know with such little detail), your code test against that.

0

精彩评论

暂无评论...
验证码 换一张
取 消