IOError: [Errno 22] Invalid argument passing clock ()

I have not had much luck finding a good explanation of what are wrong argument errors and what can cause them.

My current sample I am working with is

import sys
mylog="mylog.log"
sys.stdout = open(mylog,'w')
#lots of code
#.
#.
#.
#End of lots of code
from time import clock
print "blablabla",clock()

      

I am getting IOError Invalid Argument on the clock string. I have also tried

print "blablabla\t%s"%clock()

      

Any information on this error would be of great help. These lines work fine on short runs, this is right after the code runs while it breaks. I tried setting the buffer size to something as low as 45-100 lines.

+1


source to share


1 answer


I cannot reproduce this exact problem on my own computer, so I cannot provide specific recommendations, but here are some general comments on how to debug things like this.

When you see "Invalid Argument" in an IOError or OSError exception from python, it means the interpreter tried to make a system call that failed and set it errno

to the code EINVAL

. (Tangentially, python really shouldn't print numeric values โ€‹โ€‹for errno codes - symbolic names are standardized, but numbers aren't.) The first thing you need to do is figure out what system call it was, and the easiest way to run this program under a utility strace

. eg:

$ strace -f -o strace.log python yourscript.py [arguments...]

      

Wait for it to crash, then search for the file strace.log

for "-1 E" (this exact line). You will find something like this:



times({tms_utime=162, tms_stime=123, tms_cutime=0, tms_cstime=0}) = 1718279979
write(1, "2.85\n", 5)                   = -1 EINVAL (Invalid argument)

      

Then you read the man page for the system call failure (" man 2 write

" in this case) and look for the codename errno ( EINVAL

) in that case and see what it says went wrong.

In this case, I strongly suspect that you have discovered a bug in the Python interpreter or operating system. Invalid argument means that it says one of the input arguments to the system call had an invalid value. You are not doing anything complicated in your script, so either the interpreter messed up its system calls or the kernel misunderstood what the interpreter wanted to do.

+3


source







All Articles