Error with Python sleep() command on http://rept.i

2019-06-09 19:05发布

I'm working on a project involving the sleep() command, (running 2.7.2) and it's throwing errors that I've never seen before. Here's a test script I wrote:

from time import sleep

print '1'
sleep(2)
print '2'

It returns:

>> 1
>> Internal error: ReferenceError: _select is not defined

Any help is appreciated

1条回答
三岁会撩人
2楼-- · 2019-06-09 19:07

time.sleep() uses select if it is available. For some reason HAVE_SELECT was defined when your Python was built, but now the library can't be found.

From the docs

...
On the other hand, the precision of time() and sleep() is better than their Unix equivalents: times are expressed as floating point numbers, time() returns the most accurate time available (using Unix gettimeofday() where available), and sleep() will accept a time with a nonzero fraction (Unix select() is used to implement this, where available).
...

From the source:

floatsleep(double secs)
{
/* XXX Should test for MS_WINDOWS first! */
#if defined(HAVE_SELECT) && !defined(__BEOS__) && !defined(__EMX__)
    struct timeval t;
    double frac;
    frac = fmod(secs, 1.0);
    secs = floor(secs);
    t.tv_sec = (long)secs;
    t.tv_usec = (long)(frac*1000000.0);
    Py_BEGIN_ALLOW_THREADS
    if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
#ifdef EINTR
...

Could be that your Python was compiled for a different environment to where it is running.

Where did your Python come from? How was it compiled?

查看更多
登录 后发表回答