PyPy SUPPORT

This commit is contained in:
roberto@mrspurr
2012-03-27 13:58:27 +02:00
parent 196dc45d0b
commit ed8f0812d7
10 changed files with 65 additions and 25 deletions
+5 -2
View File
@@ -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<br/>"
yield str(env['wsgi.input'].fileno())
yield "<h1>Hello World</h1>"
yield uwsgi.cache_get('foo')
+12
View File
@@ -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();
+13
View File
@@ -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 = []
+2 -8
View File
@@ -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() {}
-5
View File
@@ -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;
+12 -6
View File
@@ -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);
+3
View File
@@ -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
+9 -3
View File
@@ -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
+5
View File
@@ -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:]
+4 -1
View File
@@ -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)