diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-06-12 00:43:51 +0000 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-06-12 00:43:51 +0000 |
| commit | fbb0ef52ee9103c02617827d31971db3688f1ed8 (patch) | |
| tree | 00b349c02f82c5eaa16f2d07fb0f1c4aaba5722a /bindings/python | |
| parent | a9b673cd4a9a5ee64d8d04f5e3c03978a799f837 (diff) | |
| download | lasso-fbb0ef52ee9103c02617827d31971db3688f1ed8.tar.gz lasso-fbb0ef52ee9103c02617827d31971db3688f1ed8.tar.xz lasso-fbb0ef52ee9103c02617827d31971db3688f1ed8.zip | |
Binding python: find a work around for random behaviour of PyImport_ImportModule
* it seems that PyImport_ImportModule is not deterministic. Sometimes it
returns True for modules which we know are present ('logging').
Importing 'sys' first seems to make 'logging' accessible (complete
cargo cult programming).
Diffstat (limited to 'bindings/python')
| -rw-r--r-- | bindings/python/wrapper_top.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index 09ceff84..76d9da95 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -611,6 +611,10 @@ static PyObject *get_logger_object() { if (_logger_object) goto exit; } + /* XXX: needed so that PyImport_ImportModule("logging") always works */ + logging_module = PyImport_ImportModule("sys"); + if (logging_module) + Py_DECREF(logging_module); logging_module = PyImport_ImportModule("logging"); if (logging_module) { _logger_object = PyObject_CallMethod(logging_module, "getLogger", @@ -633,8 +637,8 @@ lasso_python_log(G_GNUC_UNUSED const char *domain, GLogLevelFlags log_level, con char *method = NULL; if (! logger_object) { - PyErr_SetString(PyExc_RuntimeError, "both lasso.logger and " - "loggin.getLogger('lasso') did not return a logger"); + PyErr_SetString(PyExc_RuntimeError, "neither lasso.logger nor " + "logging.getLogger('lasso') did return a logger"); return; } switch (log_level) { |
