Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Nov 22, 2017

  • bpo-27535: Fix memory leak with warnings ignore
  • bpo-27535: Optimize warnings.warn()
  • C cache
  • warnings.filters becomes an immutable tuple

https://bugs.python.org/issue27535

The warnings module doesn't leak memory anymore in the hidden
warnings registry for the "ignore" action of warnings filters.

The warn_explicit() function doesn't add the warning key to the
registry anymore for the "ignore" action.
* Optimize warnings.filterwarnings(). Replace re.compile('') with
  None to avoid the cost of calling a regex.match() method, whereas
  it always matchs.
* Optimize get_warnings_attr(): replace PyObject_GetAttrString() with
  _PyObject_GetAttrId().
Make it more explicit that warnings.filters must not be replaced
directly, but modified by:

* filterwarning()
* simplefilter()
* resetwarnings()
@vstinner
Copy link
Member Author

Oh, the latest commit "warnings.filters becomes an immutable tuple" broke regrtest --huntrefleak:

haypo@selma$ ./python -m test -R 3:3 test_os -m test_access
Run tests sequentially
0:00:00 load avg: 1.76 [1/1] test_os
beginning 6 repetitions
123456
test test_os crashed -- Traceback (most recent call last):
  File "/home/haypo/prog/python/master/Lib/test/libregrtest/runtest.py", line 178, in runtest_inner
    refleak = dash_R(the_module, test, test_runner, ns.huntrleaks)
  File "/home/haypo/prog/python/master/Lib/test/libregrtest/refleak.py", line 64, in dash_R
    abcs)
  File "/home/haypo/prog/python/master/Lib/test/libregrtest/refleak.py", line 119, in dash_R_cleanup
    warnings.filters[:] = fs
TypeError: 'tuple' object does not support item assignment

@vstinner
Copy link
Member Author

While the speedup is interesting, these changes are backward incompatible and I'm not sure that it's acceptable. I prefer to close my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants