[Python-Dev] Add a developer mode to Python: -X dev command line option

Victor Stinner victor.stinner at gmail.com
Thu Nov 16 08:04:43 EST 2017


2017-11-16 13:54 GMT+01:00 Antoine Pitrou <antoine at python.org>:
> -Wdefault means -Wonce or -Walways? If the former, I don't expect many
> warnings to be emitted.

It's kind of funny that passing "-W default" changes the "default"
behaviour. "-W default" is documented as:

   "Explicitly request the default behavior (printing each warning
once per source line)."

https://docs.python.org/dev/using/cmdline.html#cmdoption-w

Default warnings filters in release mode:

$ python3 -c 'import pprint, warnings; pprint.pprint(warnings.filters)'
[('ignore', None, <class 'DeprecationWarning'>, None, 0),
 ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0),
 ('ignore', None, <class 'ImportWarning'>, None, 0),
 ('ignore', None, <class 'BytesWarning'>, None, 0),
 ('ignore', None, <class 'ResourceWarning'>, None, 0)]

-Wd adds the a warnings filter with the "default" action matching all
warnings (any kind, any message, any line number) if I understand
correctly:

$ python3 -Wd -c 'import pprint, warnings; pprint.pprint(warnings.filters)'
[('default',
  re.compile('', re.IGNORECASE),
  <class 'Warning'>,
  re.compile(''),
  0),
 ('ignore', None, <class 'DeprecationWarning'>, None, 0),
 ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0),
 ('ignore', None, <class 'ImportWarning'>, None, 0),
 ('ignore', None, <class 'BytesWarning'>, None, 0),
 ('ignore', None, <class 'ResourceWarning'>, None, 0)]

"default" and "once" actions are different:

default: "print the first occurrence of matching warnings for **each
location where the warning is issued**"
once: "print only the first occurrence of matching warnings,
**regardless of location**"


>> For example, on test_os, PYTHONMALLOC=debug increases the peak memory
>> usage from 10.5 MiB to 15.8 MiB: +50%.
>
> I see.  For my use cases, this would be acceptable :-)
>
> But I think this should be documented, for example:
>
> """Currently, developer mode adds negligible CPU time overhead, but can
> increase memory consumption significantly if many small objects are
> allocated.  This is subject to change in the future."""

+50% memory is inacceptable to develop on embedded devices, or more
generally with low level. But in that case, you are can enable options
enabled by -X dev manually, without PYTHONMALLOC=debug :-)

Ok, I will document that, I like your proposed paragraph.

Victor


More information about the Python-Dev mailing list