switching on -3 from within a program?
With a minor modification to the Makefile I was able to get mod_wsgi v2.3 to work with python2.6rc1. I promptly got a warning in my apache log files on the depcrecated use of 'sha' in the paste's cookie module, good! And easily fixed. After that I was looking for a way to switch on the -3 warnings from within my code to have extra warnings show up in my apache log file. After reading some documentation I tried from the python2.6 prompt: import sys sys.py3kwarning = True x = { 'abc': 1 }; x.has_key('abc') which does not give a warning (starting python2.6 with the -3 option of course does). Is there anyway to switch this on from within a program with a Python statement? If not, would I need to make a small C-extension module (to be imported as the first module) that sets Py_Py3WarningFlag or something else at the C level, or would that better be done by mod_wsgi's C code. Regards Anthon
Anthon van der Neut wrote:
import sys sys.py3kwarning = True x = { 'abc': 1 }; x.has_key('abc')
which does not give a warning (starting python2.6 with the -3 option of course does). Is there anyway to switch this on from within a program with a Python statement?
That doesn't work because "sys.py3kwarning = True" doesn't change the global C variable Py_Py3kWarningFlag. IIRC there is no API to change the flag from Python code.
If not, would I need to make a small C-extension module (to be imported as the first module) that sets Py_Py3WarningFlag or something else at the C level, or would that better be done by mod_wsgi's C code.
I suggest that you introduce a new config option that sets Py_Py3kWarningFlag to 1. Christian
On Tue, Sep 16, 2008 at 10:32 AM, Anthon van der Neut <avanderneut@avid.com> wrote:
With a minor modification to the Makefile I was able to get mod_wsgi v2.3 to work with python2.6rc1. I promptly got a warning in my apache log files on the depcrecated use of 'sha' in the paste's cookie module, good! And easily fixed.
After that I was looking for a way to switch on the -3 warnings from within my code to have extra warnings show up in my apache log file.
After reading some documentation I tried from the python2.6 prompt:
import sys sys.py3kwarning = True x = { 'abc': 1 }; x.has_key('abc')
which does not give a warning (starting python2.6 with the -3 option of course does).
Is there anyway to switch this on from within a program with a Python statement? If not, would I need to make a small C-extension module (to be imported as the first module) that sets Py_Py3WarningFlag or something else at the C level, or would that better be done by mod_wsgi's C code.
You could also utilize a nifty ctypes trick: import ctypes def engage_py3k_warning(): flag = ctypes.c_int.in_dll(ctypes.pythonapi, "Py_Py3kWarningFlag") flag.value = 1 -- Cheers, Benjamin Peterson "There's no place like 127.0.0.1."
Benjamin Peterson wrote:
def engage_py3k_warning(): flag = ctypes.c_int.in_dll(ctypes.pythonapi, "Py_Py3kWarningFlag") flag.value = 1
Note that tricks like this won't necessarily enable all python 3 warnings for modules that have been imported before the flag gets set. To avoid unnecessary performance penalties as a result of Py3k warnings, modules are permitted to do things like: def func(): # Do whatever if sys.py3kwarning: _orig_func = func def func(): warnings.py3kwarn("Goes away in 3.0") _orig_func() Modules that are first imported after the flag has been set will obviously have all of their warnings properly enabled. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
Hi Nick, I am aware of that (but others might not, so you are right to point this out). I did follow both Christian's and Benjamin's suggestions. The implementation at the mod_wsgi C level, which is before any module loading is more permanent, but the ctypes trick doesn't require an apache2 restart, which is somewhat more comfortable. Anthon Nick Coghlan wrote:
Benjamin Peterson wrote:
def engage_py3k_warning(): flag = ctypes.c_int.in_dll(ctypes.pythonapi, "Py_Py3kWarningFlag") flag.value = 1
Note that tricks like this won't necessarily enable all python 3 warnings for modules that have been imported before the flag gets set. To avoid unnecessary performance penalties as a result of Py3k warnings, modules are permitted to do things like:
def func(): # Do whatever
if sys.py3kwarning: _orig_func = func def func(): warnings.py3kwarn("Goes away in 3.0") _orig_func()
Modules that are first imported after the flag has been set will obviously have all of their warnings properly enabled.
Cheers, Nick.
On Sep 17, 1:32 am, Anthon van der Neut <avandern...@avid.com> wrote:
With a minor modification to the Makefile I was able to getmod_wsgi v2.3 to work with python2.6rc1.
Which I believe was still required only because you have only installed static Python library. :-)
I promptly got a warning in my apache log files on the depcrecated use of 'sha' in the paste's cookie module, good! And easily fixed.
After that I was looking for a way to switch on the -3 warnings from within my code to have extra warnings show up in my apache log file.
Check out mod_wsgi from subversion repository: svn co http://modwsgi.googlecode.com/svn/trunk/mod_wsgi and build that. When Pyhton 2.6 is being used, you should be able to have in Apache configuration file at server scope. WSGIPy3kWarningFlag On You must not be loading mod_python at same time else this will not be honoured. Graham
After reading some documentation I tried from the python2.6 prompt:
import sys sys.py3kwarning = True x = { 'abc': 1 }; x.has_key('abc')
which does not give a warning (starting python2.6 with the -3 option of course does).
Is there anyway to switch this on from within a program with a Python statement? If not, would I need to make a small C-extension module (to be imported as the first module) that sets Py_Py3WarningFlag or something else at the C level, or would that better be done bymod_wsgi'sC code.
Regards Anthon _______________________________________________ Python-Dev mailing list Python-...@python.orghttp://mail.python.org/mailman/listinfo/python-dev Unsubscribe:http://mail.python.org/mailman/options/python-dev/python-dev2-garchiv...
participants (6)
-
Anthon van der Neut
-
Anthon van der Neut
-
Benjamin Peterson
-
Christian Heimes
-
Graham Dumpleton
-
Nick Coghlan