#include <Python.h>
#include <stdlib.h>
-#include <time.h>
static PyObject *
spam_busy(PyObject *self, PyObject *args)
{
- int seconds;
- time_t start;
- long int i = 0;
+ long int count, i;
- if (!PyArg_ParseTuple(args, "i", &seconds))
+ if (!PyArg_ParseTuple(args, "l", &count))
return NULL;
Py_BEGIN_ALLOW_THREADS
- start = time(NULL);
- while (time(NULL) < start + seconds)
- i++;
+ for (i = 0; i < count; i++)
+ ;
Py_END_ALLOW_THREADS
return PyLong_FromLong(i);
}
static PyMethodDef SpamMethods[] = {
{"busy", spam_busy, METH_VARARGS,
- "Drop the GIL and run a busy wait for a few seconds."},
+ "Drop the GIL and run a busy wait until you count to `count`."},
{NULL, NULL, 0, NULL} /* Sentinel */
};