Unable to supress Python API version mismatch warning

203 views
Skip to first unread message

Mark Sapiro

unread,
Dec 24, 2009, 2:29:12 PM12/24/09
to modwsgi
Background:

I run MoinMoin on my site. I have a gdchart module (gdchart.so
library) that seems to work for MoinMoin's charting purposes, and I
have been using it in this context for some time. However, this module
was built with an older Python so whenever it is imported, Python
issues

RuntimeWarning: Python C API version mismatch for module gdchart: This
Python has API version 1012, module gdchart has version 1011.

In order to suppress this warning I added

# supress gdchart API warning
from warnings import filterwarnings
filterwarnings('ignore', 'Python C API version mismatch',
RuntimeWarning)

to my MoinMoin configuration file wikiconfig.py. This was effective
when I was running MoinMoin as a CGI.

Problem:

I have changed to running MoinMoin via WSGI and the suppression is no
longer effective. I am running WSGI in daemon mode with the following
in httpd.conf

WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess wsgi-gpc user=gpc group=gpc home=/var/www/grizz
umask=0002 display-name=wsgi-gpc
WSGIProcessGroup wsgi-gpc
WSGIScriptAlias /gpc "/var/www/grizz/moin/gpc/moin.wsgi"

When the daemon starts, the first web interaction issues

[error] /usr/lib/python2.4/site-packages/MoinMoin/config/
multiconfig.py:305: RuntimeWarning: Python C API version mismatch for
module gdchart: This Python has API version 1012, module gdchart has
version 1011.

I even tried adding

# supress gdchart API warning
from warnings import filterwarnings
filterwarnings('ignore', 'Python C API version mismatch',
RuntimeWarning)

to the beginning of the moin.wsgi script, but I still get the warning
message.

The warning itself is not a big deal, but my inability to suppress it
indicates there is something I don't understand and that is what
concerns me.

This is Apache 2.3, Python 2.4.3, mod_wsgi 3.1 and I do not load
mod_python.

Chris McDonough

unread,
Dec 24, 2009, 2:36:23 PM12/24/09
to mod...@googlegroups.com
This has almost nothing to do with mod_wsgi at all, I fear. The warning
message you're receiving come as a result of using an ".so" file generated via
compilation using one version of Python but used under another version of
Python. In the interest of protecting Graham, I'd suggest that you compile
gdchart using the version of Python used by mod_wsgi itself.

- C

> --
>
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>
>

Mark Sapiro

unread,
Dec 24, 2009, 4:22:30 PM12/24/09
to modwsgi
On Dec 24, 11:36 am, Chris McDonough <chr...@plope.com> wrote:
> This has almost nothing to do with mod_wsgi at all, I fear.  The warning
> message you're receiving come as a result of using an ".so" file generated via
> compilation using one version of Python but used under another version of
> Python.  In the interest of protecting Graham, I'd suggest that you compile
> gdchart using the version of Python used by mod_wsgi itself.


Thanks for your reply.

Please note that this question is not about gdchart per se. The
question is why can't I suppress a warning message by calling
warnings.filterwarnings()

Since posting this question I have stumbled across the new in wsgi 3.0
WSGIPythonWarnings directive, and I understand that that would
probably be effective in suppressing this warning, although I haven't
tried it. But the question still remains - why is a call to
warnings.filterwarnings() from the wsgi script not effective?

Also, I would dearly love to compile gdchart in my current Python
environment. Do you know where I can find the source?

Graham Dumpleton

unread,
Dec 25, 2009, 5:14:40 AM12/25/09
to mod...@googlegroups.com
2009/12/25 Mark Sapiro <ma...@msapiro.net>:

> On Dec 24, 11:36 am, Chris McDonough <chr...@plope.com> wrote:
>> This has almost nothing to do with mod_wsgi at all, I fear.  The warning
>> message you're receiving come as a result of using an ".so" file generated via
>> compilation using one version of Python but used under another version of
>> Python.  In the interest of protecting Graham, I'd suggest that you compile
>> gdchart using the version of Python used by mod_wsgi itself.
>
>
> Thanks for your reply.
>
> Please note that this question is not about gdchart per se. The
> question is why can't I suppress a warning message by calling
> warnings.filterwarnings()
>
> Since posting this question I have stumbled across the new in wsgi 3.0
> WSGIPythonWarnings directive, and I understand that that would
> probably be effective in suppressing this warning, although I haven't
> tried it. But the question still remains - why is a call to
> warnings.filterwarnings() from the wsgi script not effective?

From memory because warnings.filterwarnings() only works when used in
main Python interpreter and doesn't work in sub interpreters.

You can test this theory by forcing your application to run in main
Python interpreter using:

WSGIApplicationGroup %{GLOBAL}

You'll only really be able to do this if hosting the one application
in embedded mode, or only if delegating each application to separate
daemon mode process group.

WSGIPythonWarnings will work because it does its work even before
Python initialised and the settings it configures will be correctly
inherited by Python sub interpreters.

As to the warning, you are best off trying to get hold of source and
recompiling for correct version of Python.

Graham

Reply all
Reply to author
Forward
0 new messages