Ejemplo n.º 1
0
void stackless_loop(struct uwsgi_server *uwsgi) {

	int i;
	PyTaskletObject *int_tasklet;

	// tasklets main loop
	for(;;) {
		//uwsgi->async_running = -1 ;
		//if (PyStackless_GetRunCount() > 0) {
			uwsgi->async_running = 0 ;
		//}
		uwsgi->async_nevents = async_wait(uwsgi->async_queue, uwsgi->async_events, uwsgi->async, uwsgi->async_running, 0);

                if (uwsgi->async_nevents < 0) {
                        continue;
                }

		for(i=0; i<uwsgi->async_nevents;i++) {

                        if (uwsgi->async_events[i].ASYNC_FD == uwsgi->serverfd) {
				//pass the connection to the first available tasklet
				fprintf(stderr,"sending new connection...\n");
				PyChannel_Send(uwsgi->workers_channel, Py_True);
			}

		}

		/*
		if (PyStackless_GetRunCount() > 0) {
			PyStackless_Schedule(Py_None, 0);
		}
		*/

		PyStackless_RunWatchdogEx( 10, PY_WATCHDOG_TOTALTIMEOUT);

		//int_tasklet = (PyTaskletObject *) PyStackless_RunWatchdog( 1000 );
		/*
		fprintf(stderr,"done watchdog %p\n", int_tasklet);
		if (!PyTasklet_IsCurrent(int_tasklet)) {
			fprintf(stderr,"re-insert: %d\n", 1);// PyTasklet_Insert(int_tasklet));
		}
		fprintf(stderr,"recycle\n");
		*/
	}

}
Ejemplo n.º 2
0
static PyObject *
run_watchdog(PyObject *self, PyObject *args, PyObject *kwds)
{
	static char *argnames[] = {"timeout", "threadblock", "soft",
								"ignore_nesting", "totaltimeout",
								NULL};
	long timeout = 0;
	int threadblock = 0;
	int soft = 0;
	int ignore_nesting = 0;
	int totaltimeout = 0;
	int flags;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|liiii:run_watchdog",
					 argnames, &timeout, &threadblock, &soft,
					 &ignore_nesting, &totaltimeout))
		return NULL;
	flags = threadblock ? Py_WATCHDOG_THREADBLOCK : 0;
	flags |= soft ? PY_WATCHDOG_SOFT : 0;
	flags |= ignore_nesting ? PY_WATCHDOG_IGNORE_NESTING : 0;
	flags |= totaltimeout ? PY_WATCHDOG_TOTALTIMEOUT : 0;
	return PyStackless_RunWatchdogEx(timeout, flags);
}
Ejemplo n.º 3
0
PyObject *
PyStackless_RunWatchdog(long timeout)
{
	return PyStackless_RunWatchdogEx(timeout, 0);
}