diff --git a/hello_world.py b/hello_world.py index 7f4a4145..a1c5b18d 100644 --- a/hello_world.py +++ b/hello_world.py @@ -1,7 +1,10 @@ import uwsgi -#uwsgi.cache_set('/', "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello World from cache") +print uwsgi.version +print uwsgi.workers() +uwsgi.cache_set('foo', "Hello World from cache") def application(env, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) - yield "foobar" + yield "foobar
" yield str(env['wsgi.input'].fileno()) yield "

Hello World

" + yield uwsgi.cache_get('foo') diff --git a/master_utils.c b/master_utils.c index 1d670c91..804c0383 100644 --- a/master_utils.c +++ b/master_utils.c @@ -8,6 +8,18 @@ void worker_wakeup() { int uwsgi_calc_cheaper(void) { int i; + static time_t last_check = 0; + int check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL]; + + if (!last_check) last_check = time(NULL); + + time_t now = time(NULL); + if (!check_interval) + check_interval = 1; + + if ( (now - last_check) < check_interval) return 1; + + last_check = now; int needed_workers = uwsgi.cheaper_algo(); diff --git a/plugins/pypy/uwsgiplugin.py b/plugins/pypy/uwsgiplugin.py new file mode 100644 index 00000000..1c3bfbfc --- /dev/null +++ b/plugins/pypy/uwsgiplugin.py @@ -0,0 +1,13 @@ +import os,sys + +from distutils import sysconfig + +NAME='pypy' +GCC_LIST = ['../python/python_plugin', '../python/pyutils', '../python/pyloader', '../python/wsgi_handlers', '../python/wsgi_headers', '../python/wsgi_subhandler', + '../python/gil', '../python/uwsgi_pymodule', '../python/profiler', '../python/symimporter'] + +CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ] +CFLAGS.append('-DUWSGI_PYPY') + +LIBS = ['-lpypy-c'] +LDFLAGS = [] diff --git a/plugins/python/gil.c b/plugins/python/gil.c index 15da4c69..219a3bf4 100644 --- a/plugins/python/gil.c +++ b/plugins/python/gil.c @@ -3,14 +3,9 @@ extern struct uwsgi_server uwsgi; extern struct uwsgi_python up; -#ifdef UWSGI_PYPY -void gil_real_get() {} -void gil_real_release() {} -#else - void gil_real_get() { //uwsgi_log("LOCK %d\n", uwsgi.mywid); -#ifndef PYTHREE +#if !defined(PYTHREE) && !defined(UWSGI_PYPY) PyEval_AcquireLock(); PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key)); #else @@ -22,7 +17,7 @@ void gil_real_get() { void gil_real_release() { //uwsgi_log("UNLOCK %d\n", uwsgi.mywid); -#ifndef PYTHREE +#if !defined(PYTHREE) && !defined(UWSGI_PYPY) pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL)); PyEval_ReleaseLock(); #else @@ -31,7 +26,6 @@ void gil_real_release() { #endif } -#endif void gil_fake_get() {} void gil_fake_release() {} diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 399a72e9..69a907e3 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -483,9 +483,7 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) { PyObject *tmp_callable; PyObject *applications; -#ifndef UWSGI_PYPY PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi"); -#endif char *module = (char *) arg1; @@ -508,11 +506,8 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) { return NULL; } -#ifndef UWSGI_PYPY applications = PyDict_GetItemString(uwsgi_dict, "applications"); if (applications && PyDict_Check(applications)) return applications; -#endif - applications = PyDict_GetItemString(wsgi_dict, "applications"); if (applications && PyDict_Check(applications)) return applications; diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 3795cef4..503578eb 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -6,9 +6,16 @@ struct uwsgi_python up; extern struct http_status_codes hsc[]; #ifdef UWSGI_PYPY -char *RPython_StartupCode(void); + #define pypy_asm_stack_bottom() asm volatile ("/* GC_STACK_BOTTOM */" : : : \ "memory") + +char *RPython_StartupCode(void); + +extern struct pypy_pypy_module_cpyext_state_State0 pypy_g_pypy_module_cpyext_state_State; +extern struct pypy_pypy_interpreter_baseobjspace_W_Root0 *pypy_g_call_startup(void); +void pypy_g_State_startup(struct pypy_pypy_module_cpyext_state_State0 *); + void Py_Initialize(void) { pypy_asm_stack_bottom(); @@ -17,6 +24,9 @@ void Py_Initialize(void) { uwsgi_log("unable to initialize PyPy: %s\n", errmsg); exit(1); } + + pypy_g_call_startup(); + pypy_g_State_startup(&pypy_g_pypy_module_cpyext_state_State); } #endif @@ -712,11 +722,7 @@ void init_uwsgi_embedded_module() { #ifdef UNBIT if (PyDict_SetItemString(up.embedded_dict, "unbit", Py_True)) { #else - uwsgi_log("UNO\n"); - Py_INCREF(Py_None); - uwsgi_log("UNO.0\n"); - if (PyDict_SetItemString(up.embedded_dict, "unbit", &_Py_NoneStruct)) { - uwsgi_log("DUE\n"); + if (PyDict_SetItemString(up.embedded_dict, "unbit", Py_None)) { #endif PyErr_Print(); exit(1); diff --git a/plugins/python/pyutils.c b/plugins/python/pyutils.c index 9e4616bb..fc6c3468 100644 --- a/plugins/python/pyutils.c +++ b/plugins/python/pyutils.c @@ -99,12 +99,15 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch, struct wsgi //uwsgi_log("ready to call %p %p\n", callable, args); + Py_INCREF(args); + pyret = PyEval_CallObject(callable, args); //uwsgi_log("called\n"); if (PyErr_Occurred()) { + #ifndef UWSGI_PYPY int do_exit = uwsgi_python_manage_exceptions(); #else diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index aa3f820d..33640bfb 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -28,7 +28,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ #endif PyDict_SetItem(wsgi_req->async_environ, pydictkey, pydictvalue); Py_DECREF(pydictkey); - Py_DECREF(pydictvalue); + Py_DECREF(pydictvalue); } if (wsgi_req->uh.modifier1 == UWSGI_MODIFIER_MANAGE_PATH_INFO) { @@ -48,13 +48,16 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ } -#ifndef UWSGI_PYPY // if async_post is mapped as a file, directly use it as wsgi.input if (wsgi_req->async_post) { +#ifdef UWSGI_PYPY + uwsgi_log("wsgi.input mapped to a file is not supported under PyPy\n"); +#else #ifdef PYTHREE wsgi_req->async_input = PyFile_FromFd(fileno(wsgi_req->async_post), "wsgi_input", "rb", 0, NULL, NULL, NULL, 0); #else wsgi_req->async_input = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL); +#endif #endif } else { @@ -69,7 +72,6 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_req->async_input); -#endif #ifdef UWSGI_SENDFILE PyDict_SetItemString(wsgi_req->async_environ, "wsgi.file_wrapper", wi->sendfile); @@ -108,6 +110,8 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multiprocess", Py_True); } +/* + if (wsgi_req->scheme_len > 0) { zero = UWSGI_PYFROMSTRINGSIZE(wsgi_req->scheme, wsgi_req->scheme_len); } @@ -124,6 +128,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ } PyDict_SetItemString(wsgi_req->async_environ, "wsgi.url_scheme", zero); Py_DECREF(zero); +*/ wsgi_req->async_app = wi->callable; @@ -220,6 +225,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { pychunk = PyIter_Next(wsgi_req->async_placeholder); + if (!pychunk) { if (PyErr_Occurred()) { #ifndef UWSGI_PYPY diff --git a/uploadtest.py b/uploadtest.py index 9e85d83e..e64efdf8 100644 --- a/uploadtest.py +++ b/uploadtest.py @@ -5,6 +5,11 @@ import os def application(env, start_response): + print(env.__class__) + print(env['PATH_INFO']) + print(env['REQUEST_METHOD']) + print(env['wsgi.input']) + if env['PATH_INFO'].startswith('/progress/'): start_response('200 Ok', [('Content-type', 'application/json')]) filename = 'foobar/' + env['PATH_INFO'][10:] diff --git a/welcome.py b/welcome.py index 7f825409..ae3869de 100644 --- a/welcome.py +++ b/welcome.py @@ -3,7 +3,10 @@ import os import gc import sys from uwsgidecorators import * -gc.set_debug(gc.DEBUG_SAVEALL) +print(sys.version) +print(sys.version_info) +if 'set_debug' in gc.__dict__: + gc.set_debug(gc.DEBUG_SAVEALL) print(os.environ) print(sys.modules)