问题
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:
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?
来源:https://stackoverflow.com/questions/24275828/error-with-python-sleep-command-on-http-rept-it