2

This is probably a simple fix but it doesn't happen consistently so I can't figure it out.

I have a while loop that repeats if the count is less than the total. When the first loop starts, it saves the date/time. When the loop ends, I have it print both the start date/time and the end date/time. This tells the user when each loop starts and how long it took.

Here's my code:

while count < total:

    bTime = datetime.datetime.now()

    [do a bunch of work]

    print "Repeat code for: "+str(count)+" to "+str(count+15000)
    count += 15000

    print "Start time: " + str(bTime)
    print "End time: " + str(datetime.datetime.now())
print "Finished"

The problem is that it will run fine for awhile then suddenly error out and can't print datetime.now() because results are too large.

Repeat code for fields: 0 to 15000
Start time: 2018-03-07 10:43:46.612000
End time: 2018-03-07 12:03:59.211000
Repeat code for fields: 15000 to 30000
Start time: 2018-03-07 12:03:59.211000
End time: 2018-03-07 13:37:57.851000
 ...
 ...
Repeat code for fields: 135000 to 150000
Start time: 2018-03-08 00:44:11.488000
End time: 2018-03-08 02:22:44.780000
Repeat code for fields: 150000 to 165000
Start time: 2018-03-08 02:22:44.780000
ETraceback (most recent call last):
  File "FAM_meanNDVI_extraction.py", line 210, in <module>
    print "End time: " + str(datetime.datetime.now())
IOError: [Errno 34] Result too large

If anyone has an idea why it's doing this, I would greatly appreciate the help. Honestly if I just delete that line it'll work fine and I could move on with my life but it's just something nice to have for the user.

martineau
  • 119,623
  • 25
  • 170
  • 301
Myco
  • 101
  • 2
  • 10
  • This is an interesting question. Just googling it yields a Python + Windows issue: https://bugs.python.org/issue25155 (may contain something that jumps out at you, slightly different failure mode/stacktrace though) – user268396 Mar 08 '18 at 19:15
  • Try removing (or skipping) the "bunch of work" and see what happens. – martineau Mar 08 '18 at 19:16
  • Also this one: https://stackoverflow.com/questions/20201706/overflowerror-34-result-too-large/20201845 – user268396 Mar 08 '18 at 19:17
  • similar to @user268396 I found that previous stackoverflow example. What is puzzling to me is that you seem to be overflowing the float size on a datetime which doesn't make any sense, it should not be remotely large enough to do that. Overflowing it with stuff in your calculation seems more likely, but the stack trace doesn't seem to support that – Lost Mar 08 '18 at 19:26

2 Answers2

0

Try this:

print "End time: ",
print datetime.datetime.now()
XlbrlX
  • 743
  • 1
  • 6
  • 10
  • Tried this yesterday and it ran the whole thing fine. Error free. But I don't understand how splitting the print up works but with them together it doesn't. – Myco Mar 09 '18 at 18:31
  • By splitting you avoid doing two things: 1) Casting datetime.datetime.now() into str and 2) concatenating two strings using +. – XlbrlX Mar 09 '18 at 18:33
0

IOerror is usually associated with "disk full" or "file not found".

https://docs.python.org/2/library/exceptions.html#exceptions.IOError

I suspect this is because your console and not because of datetime. Try to skip printing anything on console and then try. It should keep running or throw some other error :P.

Tejas
  • 284
  • 2
  • 8