Python时间。时间()>爱

2024-09-30 22:23:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚安装了一个基本的GentooStage3,当我尝试调用时,出现以下错误时间。时间():

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

我发现这个是因为当我试着跑出来的时候我得到:

^{pr2}$

这是一个自定义内核,我只是确保我编译了RTC支持,但仍然没有运气。你知道为什么会这样吗?在


Tags: importtimeontype错误时间helpmay
2条回答

这是你的问题?在

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

编辑C测试代码

#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);
}

如果我用gcc -DHAVE_GETTIMEOFDAY testtime.c编译这个文件,我得到一个工作时间输出,这就是python的秘密。在

也许在嵌入式平台上,你需要让python相信c库提供的时间函数是错误的,或者kernel/c lib位出现了问题

它在你的自定义内核之前工作吗?启动到一个救援CD,chroot进入你的gentoo env,然后运行你的脚本。如果它能工作,它就是你的内核。这是我能说的最具体的了。在

相关问题 更多 >