static PyObject * time_clock_settime(PyObject *self, PyObject *args) { int clk_id; PyObject *obj; _PyTime_t t; struct timespec tp; int ret; if (!PyArg_ParseTuple(args, "iO:clock_settime", &clk_id, &obj)) return NULL; if (_PyTime_FromSecondsObject(&t, obj, _PyTime_ROUND_FLOOR) < 0) return NULL; if (_PyTime_AsTimespec(t, &tp) == -1) return NULL; ret = clock_settime((clockid_t)clk_id, &tp); if (ret != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } Py_RETURN_NONE; }
static PyObject * time_sleep(PyObject *self, PyObject *obj) { _PyTime_t secs; if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING)) return NULL; if (secs < 0) { PyErr_SetString(PyExc_ValueError, "sleep length must be non-negative"); return NULL; } if (pysleep(secs) != 0) return NULL; Py_RETURN_NONE; }
static PyObject * _queue_SimpleQueue_get_impl(simplequeueobject *self, int block, PyObject *timeout) /*[clinic end generated code: output=ec82a7157dcccd1a input=4bf691f9f01fa297]*/ { _PyTime_t endtime = 0; _PyTime_t timeout_val; PyObject *item; PyLockStatus r; PY_TIMEOUT_T microseconds; if (block == 0) { /* Non-blocking */ microseconds = 0; } else if (timeout != Py_None) { /* With timeout */ if (_PyTime_FromSecondsObject(&timeout_val, timeout, _PyTime_ROUND_CEILING) < 0) return NULL; if (timeout_val < 0) { PyErr_SetString(PyExc_ValueError, "'timeout' must be a non-negative number"); return NULL; } microseconds = _PyTime_AsMicroseconds(timeout_val, _PyTime_ROUND_CEILING); if (microseconds >= PY_TIMEOUT_MAX) { PyErr_SetString(PyExc_OverflowError, "timeout value is too large"); return NULL; } endtime = _PyTime_GetMonotonicClock() + timeout_val; } else { /* Infinitely blocking */ microseconds = -1; } /* put() signals the queue to be non-empty by releasing the lock. * So we simply try to acquire the lock in a loop, until the condition * (queue non-empty) becomes true. */ while (self->lst_pos == PyList_GET_SIZE(self->lst)) { /* First a simple non-blocking try without releasing the GIL */ r = PyThread_acquire_lock_timed(self->lock, 0, 0); if (r == PY_LOCK_FAILURE && microseconds != 0) { Py_BEGIN_ALLOW_THREADS r = PyThread_acquire_lock_timed(self->lock, microseconds, 1); Py_END_ALLOW_THREADS } if (r == PY_LOCK_INTR && Py_MakePendingCalls() < 0) { return NULL; } if (r == PY_LOCK_FAILURE) { /* Timed out */ PyErr_SetNone(EmptyError); return NULL; } self->locked = 1; /* Adjust timeout for next iteration (if any) */ if (endtime > 0) { timeout_val = endtime - _PyTime_GetMonotonicClock(); microseconds = _PyTime_AsMicroseconds(timeout_val, _PyTime_ROUND_CEILING); } }