| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,43 @@ | |||
| 1 | + import contextlib | ||
| 2 | + import sys | ||
| 3 | + import types | ||
| 4 | + import warnings | ||
| 5 | + | ||
| 6 | + from test.support import warnings_helper as orig | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + @contextlib.contextmanager | ||
| 10 | + def ignore_warnings(*, category, message=''): | ||
| 11 | + """Decorator to suppress warnings. | ||
| 12 | + | ||
| 13 | + Can also be used as a context manager. This is not preferred, | ||
| 14 | + because it makes diffs more noisy and tools like 'git blame' less useful. | ||
| 15 | + But, it's useful for async functions. | ||
| 16 | + """ | ||
| 17 | + with warnings.catch_warnings(): | ||
| 18 | + warnings.filterwarnings('ignore', category=category, message=message) | ||
| 19 | + yield | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + @contextlib.contextmanager | ||
| 23 | + def ignore_fork_in_thread_deprecation_warnings(): | ||
| 24 | + """Suppress deprecation warnings related to forking in multi-threaded code. | ||
| 25 | + | ||
| 26 | + See gh-135427 | ||
| 27 | + | ||
| 28 | + Can be used as decorator (preferred) or context manager. | ||
| 29 | + """ | ||
| 30 | + with ignore_warnings( | ||
| 31 | + message=".*fork.*may lead to deadlocks in the child.*", | ||
| 32 | + category=DeprecationWarning, | ||
| 33 | + ): | ||
| 34 | + yield | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + if sys.version_info >= (3, 15): | ||
| 38 | + warnings_helper = orig | ||
| 39 | + else: | ||
| 40 | + warnings_helper = types.SimpleNamespace( | ||
| 41 | + ignore_fork_in_thread_deprecation_warnings=ignore_fork_in_thread_deprecation_warnings, | ||
| 42 | + **vars(orig), | ||
| 43 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | ) | |
| 15 | 15 | ||
| 16 | 16 | from . import fixtures | |
| 17 | + from .compat.py314 import warnings_helper | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | class TestZip(fixtures.ZipFixtures, unittest.TestCase): | |
@@ -50,6 +51,7 @@ def test_one_distribution(self): | |||
| 50 | 51 | dists = list(distributions(path=sys.path[:1])) | |
| 51 | 52 | assert len(dists) == 1 | |
| 52 | 53 | ||
| 54 | + @warnings_helper.ignore_fork_in_thread_deprecation_warnings() | ||
| 53 | 55 | @unittest.skipUnless( | |
| 54 | 56 | hasattr(os, 'register_at_fork') | |
| 55 | 57 | and 'fork' in multiprocessing.get_all_start_methods(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments