开发者

Python time.time() -> IOError

开发者 https://www.devze.com 2023-03-08 04:23 出处:网络
I\'ve just installed a base gentoo stage 3 and I get the following error when i try and call time.time():

I've just installed a base gentoo stage 3 and I get the following error when i try and call time.time():

sbx / # python
import time
Python 2.7.1 (r271:86832, May 22 2011, 14:53:09)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.time()
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 0] Error

I found this because when I try and run emerge I开发者_如何学JAVA get:

sbx / # emerge
Traceback (most recent call last):
  File "/usr/bin/emerge", line 32, in 
    from _emerge.main import emerge_main
  File "/usr/lib/portage/pym/_emerge/main.py", line 6, in 
    import logging
  File "/usr/lib/python2.7/logging/__init__.py", line 94, in 
    _startTime = time.time()
IOError: [Errno 11] Resource temporarily unavailable

This is a custom kernel and I just made sure I compiled in RTC support, but still no luck. Any ideas on why this is happening?


Did it work before your custom kernel? Boot into a rescue CD, chroot into your gentoo env, and run your script. If it works, it's your kernel. That's about as specific as I can be.


Prehaps this is your issue ?

http://bugs.gentoo.org/show_bug.cgi?id=330937

edit C test code

#include <stdio.h>
#include <sys/time.h>

typedef struct timeval _PyTime_timeval;

void _PyTime_gettimeofday(_PyTime_timeval *tp)
{
    /* There are three ways to get the time:
      (1) gettimeofday() -- resolution in microseconds
      (2) ftime() -- resolution in milliseconds
      (3) time() -- resolution in seconds
      In all cases the return value in a timeval struct.
      Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
      fail, so we fall back on ftime() or time().
      Note: clock resolution does not imply clock accuracy! */
#ifdef HAVE_GETTIMEOFDAY
#ifdef GETTIMEOFDAY_NO_TZ
    if (gettimeofday(tp) == 0)
        return;
#else /* !GETTIMEOFDAY_NO_TZ */
    if (gettimeofday(tp, (struct timezone *)NULL) == 0)
        return;
#endif /* !GETTIMEOFDAY_NO_TZ */
#endif /* !HAVE_GETTIMEOFDAY */
#if defined(HAVE_FTIME)
    {
        struct timeb t;
        ftime(&t);
        tp->tv_sec = t.time;
        tp->tv_usec = t.millitm * 1000;
    }
#else /* !HAVE_FTIME */
    tp->tv_sec = time(NULL);
    tp->tv_usec = 0;
#endif /* !HAVE_FTIME */
    return;
}


int main(int argc, char** argv) {
    _PyTime_timeval time;
    _PyTime_gettimeofday(&time);
    double tval = 0;
    tval = (double) time.tv_sec + time.tv_usec * 0.000001;

    printf("Time value was %f\n", tval);
}

If I compile this with gcc -DHAVE_GETTIMEOFDAY testtime.c I get a working time output, this is what python is boiling down to under the hood.

Maybe being on an embedded platform you need to convince python that your time function provided by the c library is wrong, or something is going awray in the kernel / C lib bits

0

精彩评论

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