void run_game_engine(void) { printf("Game Engine was started\n"); while (PyStackless_GetRunCount() > 0) { /* note that we are not a tasklet in this context */ printf("Game is computing for 1 second.\n"); pysleep(1.0); if (wrap(PyStackless_Schedule(Py_None, 0))) return; } printf("Game Engine is shutting down.\n"); }
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; }