4

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 for 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?

Joseph Turian
  • 15,430
  • 14
  • 47
  • 62
  • `usersystime` might be the culprit. Can you give code used to calculate this value? – moinudin Jan 11 '11 at 23:39
  • Makes no sense... How about wrapping that code on `try: ... except OverflowError: print usersystime, os.times()`? – TryPyPy Jan 16 '11 at 10:56

1 Answers1

1

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.

Community
  • 1
  • 1
PaoloVictor
  • 1,296
  • 8
  • 18