Пример #1
0
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");
}
Пример #2
0
static PyObject *
schedule_generic(PyObject *self, PyObject *args, PyObject *kwds, int remove)
{
	STACKLESS_GETARG();
	PyObject *retval = (PyObject *) PyThreadState_GET()->st.current;
	static char *argnames[] = {"retval", NULL};

	if (PyTuple_GET_SIZE(args) > 0) {
		if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:schedule",
						 argnames, &retval))
			return NULL;
	}
	STACKLESS_PROMOTE_ALL();
	return PyStackless_Schedule(retval, remove);
}
Пример #3
0
static PyObject *
sleepInCpp(PyObject *self, PyObject *seconds)
{
	double time_to_wait, wait_until;
	time_to_wait = PyFloat_AsDouble(seconds);
	if (PyErr_Occurred())
		return NULL;
	wait_until = pytime() + time_to_wait;
	while (pytime() < wait_until) {
		/* let other processes run */
		printf("sleepInCpp activated\n");
		if (wrap(PyStackless_Schedule(Py_None, 0)))
			return NULL;
	}
	Py_INCREF(Py_None);
	return Py_None;
}
Пример #4
0
PyObject *
PyStackless_Schedule_nr(PyObject *retval, int remove)
{
	STACKLESS_PROPOSE_ALL();
	return PyStackless_Schedule(retval, remove);
}
Пример #5
0
static PyObject *
slpmodule_reduce(PyObject *self)
{
	return PyObject_GetAttrString(slp_module, "__name__");
}

/******************************************************

  some test functions

 ******************************************************/


static char test_cframe__doc__[] =
"test_cframe(switches, words=0) -- a builtin testing function that does nothing\n\
but tasklet switching. The function will call PyStackless_Schedule() for switches\n\
times and then finish.\n\
If words is given, as many words will be allocated on the C stack.\n\
Usage: Create two tasklets for test_cframe and run them by run().\n\
\n\
    t1 = tasklet(test_cframe)(500000)\n\
    t2 = tasklet(test_cframe)(500000)\n\
    run()\n\
This can be used to measure the execution time of 1.000.000 switches.";

/* we define the stack max as the typical recursion limit
 * times the typical number of words per recursion.
 * That is 1000 * 64
 */

#define STACK_MAX_USEFUL 64000