static PyGreenlet * PyGreenlet_New(PyObject *run, PyGreenlet *parent) { PyGreenlet* g = NULL; g = (PyGreenlet *) PyType_GenericAlloc(&PyGreenlet_Type, 0); if (g == NULL) { return NULL; } if (run != NULL) { Py_INCREF(run); g->run_info = run; } if (parent != NULL) { if (PyGreenlet_SetParent(g, parent)) { Py_DECREF(g); return NULL; } } else { if ((g->parent = PyGreenlet_GetCurrent()) == NULL) { Py_DECREF(g); return NULL; } } return g; }
struct wsgi_request *uwsgi_greenlet_current_wsgi_req(void) { struct wsgi_request *wsgi_req = NULL; PyObject *current_greenlet = (PyObject *)PyGreenlet_GetCurrent(); PyObject *py_wsgi_req = PyObject_GetAttrString(current_greenlet, "uwsgi_wsgi_req"); // not in greenlet if (!py_wsgi_req) { uwsgi_log("[BUG] current_wsgi_req NOT FOUND !!!\n"); goto end; } wsgi_req = (struct wsgi_request*) PyLong_AsLong(py_wsgi_req); Py_DECREF(py_wsgi_req); end: Py_DECREF(current_greenlet); return wsgi_req; }
void greenlet_init_apps(void) { if (!ugl.enabled) { return; } PyGreenlet_Import(); ugl.gl = uwsgi_malloc( sizeof(PyGreenlet *) * uwsgi.async ); ugl.main = PyGreenlet_GetCurrent(); ugl.callable = PyCFunction_New(uwsgi_greenlet_request_method, NULL); uwsgi_log("enabled greenlet engine\n"); uwsgi.schedule_to_main = greenlet_schedule_to_main; uwsgi.schedule_to_req = greenlet_schedule_to_req; return; }