Skip to content

Commit

Permalink
TODO: survive to dynamic loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@debian32 committed Jun 25, 2011
1 parent 9b7cbab commit df0f2a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion plugins/python/pyloader.c
Expand Up @@ -524,7 +524,10 @@ PyObject *uwsgi_file_loader(void *arg1) {
if (!callable) callable = "application";

wsgi_file_module = uwsgi_pyimport_by_filename("uwsgi_wsgi_file", filename);
// no need to check here for module import as it is already done by uwsgi_pyimport_by_file
if (!wsgi_file_module) {
PyErr_Print();
exit(1);
}

wsgi_file_dict = PyModule_GetDict(wsgi_file_module);
if (!wsgi_file_dict) {
Expand Down
22 changes: 15 additions & 7 deletions plugins/python/python_plugin.c
Expand Up @@ -195,12 +195,12 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
pyfile = fopen(filename, "r");
if (!pyfile) {
uwsgi_log("failed to open python file %s\n", filename);
exit(1);
return NULL;
}

if (fstat(fileno(pyfile), &pystat)) {
uwsgi_error("fstat()");
exit(1);
return NULL;
}

if (S_ISDIR(pystat.st_mode)) {
Expand All @@ -210,15 +210,19 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
pyfile = fopen(real_filename, "r");
if (!pyfile) {
uwsgi_error_open(real_filename);
exit(1);
free(real_filename);
fclose(pyfile);
return NULL;
}
}

py_file_node = PyParser_SimpleParseFile(pyfile, real_filename, Py_file_input);
if (!py_file_node) {
PyErr_Print();
uwsgi_log("failed to parse file %s\n", real_filename);
exit(1);
free(real_filename);
fclose(pyfile);
return NULL;
}

fclose(pyfile);
Expand All @@ -232,7 +236,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
if (!py_file_node) {
PyErr_Print();
uwsgi_log("failed to parse url %s\n", real_filename);
exit(1);
return NULL;
}
}
}
Expand All @@ -242,13 +246,13 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
if (!py_compiled_node) {
PyErr_Print();
uwsgi_log("failed to compile python file %s\n", real_filename);
exit(1);
return NULL;
}

py_file_module = PyImport_ExecCodeModule(name, py_compiled_node);
if (!py_file_module) {
PyErr_Print();
exit(1);
return NULL;
}

Py_DECREF(py_compiled_node);
Expand Down Expand Up @@ -371,6 +375,10 @@ void init_uwsgi_vars() {
else {
// this is a filepath that need to be mapped
tmp_module = uwsgi_pyimport_by_filename(up.pymodule_alias[i], value + 1);
if (!tmp_module) {
PyErr_Print();
exit(1);
}
}
uwsgi_log("mapped virtual pymodule \"%s\" to real pymodule \"%s\"\n", up.pymodule_alias[i], value + 1);
// reset original value
Expand Down

0 comments on commit df0f2a5

Please sign in to comment.