From cceee511f2ac37a82fccaed9a0d817f7d1d4e916 Mon Sep 17 00:00:00 2001 From: "roberto@mrspurr" Date: Fri, 6 Apr 2012 07:40:21 +0200 Subject: [PATCH] added support for reload-on-exception on PyPy and interval-based cron syntax --- master_utils.c | 80 +++++++++++++++++++++++--------- plugins/pypy/uwsgiplugin.py | 2 +- plugins/python/pyloader.c | 10 ++-- plugins/python/python_plugin.c | 2 +- plugins/python/pyutils.c | 12 +---- plugins/python/wsgi_subhandler.c | 4 -- 6 files changed, 65 insertions(+), 45 deletions(-) diff --git a/master_utils.c b/master_utils.c index 804c0383..006007f5 100644 --- a/master_utils.c +++ b/master_utils.c @@ -545,20 +545,36 @@ void uwsgi_manage_signal_cron(time_t now) { uc_month = ucron->month; uc_week = ucron->week; - if (ucron->minute == -1) - uc_minute = uwsgi_cron_delta->tm_min; - if (ucron->hour == -1) - uc_hour = uwsgi_cron_delta->tm_hour; - if (ucron->month == -1) - uc_month = uwsgi_cron_delta->tm_mon; - if (ucron->day == -1) - uc_day = uwsgi_cron_delta->tm_mday; - if (ucron->week == -1) - uc_week = uwsgi_cron_delta->tm_wday; + // negative values as interval -1 = * , -5 = */5 + if (ucron->minute < 0) { + if ((uwsgi_cron_delta->tm_min % abs(ucron->minute)) == 0) { + uc_minute = uwsgi_cron_delta->tm_min; + } + } + if (ucron->hour < 0) { + if ((uwsgi_cron_delta->tm_hour % abs(ucron->hour)) == 0) { + uc_hour = uwsgi_cron_delta->tm_hour; + } + } + if (ucron->month < 0) { + if ((uwsgi_cron_delta->tm_mon % abs(ucron->month)) == 0) { + uc_month = uwsgi_cron_delta->tm_mon; + } + } + if (ucron->day < 0) { + if ((uwsgi_cron_delta->tm_mday % abs(ucron->day)) == 0) { + uc_day = uwsgi_cron_delta->tm_mday; + } + } + if (ucron->week < 0) { + if ((uwsgi_cron_delta->tm_wday % abs(ucron->week)) == 0) { + uc_week = uwsgi_cron_delta->tm_wday; + } + } int run_task = 0; // mday and wday are ORed - if (ucron->day != -1 && ucron->week != -1) { + if (ucron->day >= 0 && ucron->week >= 0) { if (uwsgi_cron_delta->tm_min == uc_minute && uwsgi_cron_delta->tm_hour == uc_hour && uwsgi_cron_delta->tm_mon == uc_month && (uwsgi_cron_delta->tm_mday == uc_day || uwsgi_cron_delta->tm_wday == uc_week)) { run_task = 1; } @@ -602,8 +618,10 @@ void uwsgi_manage_command_cron(time_t now) { return; } - while (current_cron) { + // fix month + uwsgi_cron_delta->tm_mon++; + while (current_cron) { uc_minute = current_cron->minute; uc_hour = current_cron->hour; @@ -611,20 +629,36 @@ void uwsgi_manage_command_cron(time_t now) { uc_month = current_cron->month; uc_week = current_cron->week; - if (current_cron->minute == -1) - uc_minute = uwsgi_cron_delta->tm_min; - if (current_cron->hour == -1) - uc_hour = uwsgi_cron_delta->tm_hour; - if (current_cron->month == -1) - uc_month = uwsgi_cron_delta->tm_mon; - if (current_cron->day == -1) - uc_day = uwsgi_cron_delta->tm_mday; - if (current_cron->week == -1) - uc_week = uwsgi_cron_delta->tm_wday; + // negative values as interval -1 = * , -5 = */5 + if (current_cron->minute < 0) { + if ((uwsgi_cron_delta->tm_min % abs(current_cron->minute)) == 0) { + uc_minute = uwsgi_cron_delta->tm_min; + } + } + if (current_cron->hour < 0) { + if ((uwsgi_cron_delta->tm_hour % abs(current_cron->hour)) == 0) { + uc_hour = uwsgi_cron_delta->tm_hour; + } + } + if (current_cron->month < 0) { + if ((uwsgi_cron_delta->tm_hour % abs(current_cron->month)) == 0) { + uc_month = uwsgi_cron_delta->tm_mon; + } + } + if (current_cron->day < 0) { + if ((uwsgi_cron_delta->tm_mday % abs(current_cron->day)) == 0) { + uc_day = uwsgi_cron_delta->tm_mday; + } + } + if (current_cron->week < 0) { + if ((uwsgi_cron_delta->tm_wday % abs(current_cron->week)) == 0) { + uc_week = uwsgi_cron_delta->tm_wday; + } + } int run_task = 0; // mday and wday are ORed - if (current_cron->day != -1 && current_cron->week != -1) { + if (current_cron->day >= 0 && current_cron->week >= 0) { if (uwsgi_cron_delta->tm_min == uc_minute && uwsgi_cron_delta->tm_hour == uc_hour && uwsgi_cron_delta->tm_mon == uc_month && (uwsgi_cron_delta->tm_mday == uc_day || uwsgi_cron_delta->tm_wday == uc_week)) { run_task = 1; } diff --git a/plugins/pypy/uwsgiplugin.py b/plugins/pypy/uwsgiplugin.py index 1c3bfbfc..2690ae02 100644 --- a/plugins/pypy/uwsgiplugin.py +++ b/plugins/pypy/uwsgiplugin.py @@ -4,7 +4,7 @@ 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'] + '../python/web3_subhandler', '../python/pump_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') diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 965f128f..e2060e6e 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -277,7 +277,6 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre wi->response_subhandler = uwsgi_response_subhandler_wsgi; wi->argc = 2; } -#ifndef UWSGI_PYPY else if (app_type == PYTHON_APP_TYPE_WEB3) { #ifdef UWSGI_DEBUG uwsgi_log("-- Web3 callable selected --\n"); @@ -292,7 +291,6 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre wi->request_subhandler = uwsgi_request_subhandler_pump; wi->response_subhandler = uwsgi_response_subhandler_pump; } -#endif #ifdef UWSGI_ASYNC wi->args = malloc(sizeof(PyObject*)*uwsgi.cores); @@ -712,8 +710,10 @@ PyObject *uwsgi_paste_loader(void *arg1) { PyObject *uwsgi_eval_loader(void *arg1) { -#ifndef UWSGI_PYPY - +#ifdef UWSGI_PYPY + uwsgi_log("the eval loader is currently not supported under PyPy !!!\n"); + return NULL; +#else char *code = (char *) arg1; PyObject *wsgi_eval_module, *wsgi_eval_callable = NULL; @@ -769,8 +769,6 @@ PyObject *uwsgi_eval_loader(void *arg1) { } return wsgi_eval_callable; -#else - return NULL; #endif } diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index e54f1025..b4e3e2c6 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -321,9 +321,9 @@ UWSGI_RELEASE_GIL PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { #ifdef UWSGI_PYPY + uwsgi_log("import by filename is currently not supported on PyPy !!!\n"); return NULL; #else - FILE *pyfile; struct _node *py_file_node = NULL; PyObject *py_compiled_node, *py_file_module; diff --git a/plugins/python/pyutils.c b/plugins/python/pyutils.c index 084ace75..a9f23798 100644 --- a/plugins/python/pyutils.c +++ b/plugins/python/pyutils.c @@ -8,17 +8,16 @@ int manage_python_response(struct wsgi_request *wsgi_req) { return uwsgi_response_subhandler_wsgi(wsgi_req); } -#ifndef UWSGI_PYPY char *uwsgi_python_get_exception_type(PyObject *exc) { char *class_name = NULL; -#ifndef PYTHREE +#if !defined(PYTHREE) && !defined(UWSGI_PYPY) if (PyClass_Check(exc)) { class_name = PyString_AsString( ((PyClassObject*)(exc))->cl_name ); } else { #endif class_name = (char *) ((PyTypeObject*)exc)->tp_name; -#ifndef PYTHREE +#if !defined(PYTHREE) && !defined(UWSGI_PYPY) } #endif @@ -91,7 +90,6 @@ int uwsgi_python_manage_exceptions(void) { return ret; } -#endif PyObject *python_call(PyObject *callable, PyObject *args, int catch, struct wsgi_request *wsgi_req) { @@ -104,11 +102,7 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch, struct wsgi if (PyErr_Occurred()) { -#ifndef UWSGI_PYPY int do_exit = uwsgi_python_manage_exceptions(); -#else - int do_exit = 0; -#endif if (PyErr_ExceptionMatches(PyExc_MemoryError)) { uwsgi_log("Memory Error detected !!!\n"); @@ -227,9 +221,7 @@ void init_pyargv() { } -#ifndef UWSGI_PYPY PySys_SetArgv(up.argc, up.py_argv); -#endif PyObject *sys_dict = get_uwsgi_pydict("sys"); if (!sys_dict) { diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index 9f4453ea..3707ddf0 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -216,11 +216,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { if (!pychunk) { if (PyErr_Occurred()) { -#ifndef UWSGI_PYPY int do_exit = uwsgi_python_manage_exceptions(); -#else - int do_exit = 0; -#endif if (PyErr_ExceptionMatches(PyExc_MemoryError)) { uwsgi_log("Memory Error detected !!!\n"); }