Title: warnings raised by test_peg_generator when setuptools_scm is installed · Issue #133509 · python/cpython · GitHub
Open Graph Title: warnings raised by test_peg_generator when setuptools_scm is installed · Issue #133509 · python/cpython
X Title: warnings raised by test_peg_generator when setuptools_scm is installed · Issue #133509 · python/cpython
Description: Bug report Bug description: Hi, since #131802, we see test_peg_generator failing with the following warning: Warning -- logging._handlerList was modified by test_peg_generator Warning -- Before: (140617884985088, [ Open Graph Description: Bug report Bug description: Hi, since #131802, we see test_peg_generator failing with the following warning: Warning -- logging._handlerList was modified by test_peg_generator Warning -- Before: (1...
X Description: Bug report Bug description: Hi, since #131802, we see test_peg_generator failing with the following warning: Warning -- logging._handlerList was modified by test_peg_generator Warning -- Before: (1...
Opengraph URL: https://github.com/python/cpython/issues/133509
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"warnings raised by test_peg_generator when setuptools_scm is installed","articleBody":"# Bug report\n\n### Bug description:\n\nHi, since #131802, we see `test_peg_generator` failing with the following warning:\n```\nWarning -- logging._handlerList was modified by test_peg_generator\nWarning -- Before: (140617884985088, [\u003cweakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620\u003e, \u003cweakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0\u003e], [\u003cweakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620\u003e])\nWarning -- After: (140617884985088, [\u003cweakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620\u003e, \u003cweakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0\u003e], [\u003cweakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620\u003e, \u003cweakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0\u003e])\n```\n\nFor some reason, during the execution, second reference to the same 'setuptools_scm._log.AlwaysStdErrHandler' appears in the `_handlerList`.\n\nWhen I remove `setuptools_scm`, the issue is gone.\n\nInterestingly (at least to me), when I revert changes done in #131802 in `lib/test/support/__init__.py` and `os_helper.py` (commenting out `import logging` is enough), the issue is gone as well, so it seems like some weird side effect of the import?\n\nI tried to track the issue and got through setuptools all the way to `ep.load()` in `finalize_options()` which triggers the issue (see trace below).\n\nI added some debug prints to `_addHandlerRef` function, and it's apparently called only once with this handler. Though I also see a single call for the `logging._StderrHandler'` and it's there twice as well, so I am probably overlooking something...\n\nHere is the trace from when the handler ref is being added during the test execution:\n```pytb\n.....\n File \"/build/cpython-3.13/Lib/test/test_peg_generator/test_c_parser.py\", line 131, in build_extension\n generate_parser_c_extension(grammar, Path('.'), library_dir=self.library_dir)\n File \"/build/cpython-3.13/Tools/peg_generator/pegen/testutil.py\", line 107, in generate_parser_c_extension\n compile_c_extension(\n File \"/build/cpython-3.13/Tools/peg_generator/pegen/build.py\", line 160, in compile_c_extension\n dist = Distribution({\"name\": extension_name, \"ext_modules\": [extension]})\n File \"/usr/lib/python3.13/vendor-packages/setuptools/dist.py\", line 323, in __init__\n _Distribution.__init__(self, dist_attrs)\n File \"/usr/lib/python3.13/vendor-packages/setuptools/_distutils/dist.py\", line 309, in __init__\n self.finalize_options()\n File \"/usr/lib/python3.13/vendor-packages/setuptools/dist.py\", line 787, in finalize_options\n for ep in sorted(loaded, key=by_order):\n File \"/usr/lib/python3.13/vendor-packages/setuptools/dist.py\", line 786, in \u003clambda\u003e\n loaded = map(lambda e: e.load(), filtered)\n File \"/build/cpython-3.13/Lib/importlib/metadata/__init__.py\", line 179, in load\n module = import_module(match.group('module'))\n File \"/build/cpython-3.13/Lib/importlib/__init__.py\", line 88, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1387, in _gcd_import\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1360, in _find_and_load\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1310, in _find_and_load_unlocked\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1387, in _gcd_import\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1360, in _find_and_load\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1310, in _find_and_load_unlocked\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1387, in _gcd_import\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1360, in _find_and_load\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1331, in _find_and_load_unlocked\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 935, in _load_unlocked\n File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 1026, in exec_module\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"/usr/lib/python3.13/vendor-packages/setuptools_scm/__init__.py\", line 8, in \u003cmodule\u003e\n from ._config import DEFAULT_LOCAL_SCHEME\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1360, in _find_and_load\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1331, in _find_and_load_unlocked\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 935, in _load_unlocked\n File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 1026, in exec_module\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"/usr/lib/python3.13/vendor-packages/setuptools_scm/_config.py\", line 15, in \u003cmodule\u003e\n from . import _log\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1415, in _handle_fromlist\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1360, in _find_and_load\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 1331, in _find_and_load_unlocked\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 935, in _load_unlocked\n File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 1026, in exec_module\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 488, in _call_with_frames_removed\n File \"/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py\", line 48, in \u003cmodule\u003e\n _default_handler = make_default_handler()\n File \"/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py\", line 43, in make_default_handler\n handler = AlwaysStdErrHandler()\n File \"/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py\", line 23, in __init__\n super().__init__(sys.stderr)\n File \"/build/cpython-3.13/Lib/logging/__init__.py\", line 1128, in __init__\n Handler.__init__(self)\n File \"/build/cpython-3.13/Lib/logging/__init__.py\", line 941, in __init__\n _addHandlerRef(self)\n```\n\nAll this is with Python 3.13 (latest changes), setuptools 80.3.1, setuptools_scm 8.3.1, and on Oracle Solaris, but I don't think this is necessarily platform dependent.\n\nI also reproduced this with older setuptools 73.0.1 and setuptools_scm 8.1.0.\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nOther","author":{"url":"https://github.com/kulikjak","@type":"Person","name":"kulikjak"},"datePublished":"2025-05-06T12:06:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/133509/cpython/issues/133509"}
route-pattern /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) route-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:9f9375e2-0d22-2b2d-eb1e-dc7e80fd6b61 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id E916:25EC2E:2ED4087:3F16094:6A53C26E html-safe-nonce b77eb5983f8885bcf24fcf7d830037510a2dc5680b7982d9e63d15d9b391495f visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTE2OjI1RUMyRToyRUQ0MDg3OjNGMTYwOTQ6NkE1M0MyNkUiLCJ2aXNpdG9yX2lkIjoiNDU4ODY1MjkxODA1NjY2NTcxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac 35aa0f0bfab62af510648e3ed4e1eb9969d2f2f5f33ff5b73b2cf9b79a15f0c8 hovercard-subject-tag issue:3042609779 github-keyboard-shortcuts repository,issues,copilot google-site-verification Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I octolytics-url https://collector.github.com/github/collect analytics-location / fb:app_id 1401488693436528 apple-itunes-app app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/133509/issue_layout twitter:image https://opengraph.githubassets.com/7332ebd407d3e17f68ad89bb637cf6a8aec3ae71dc4df677641ee3f650e3260a/python/cpython/issues/133509 twitter:card summary_large_image og:image https://opengraph.githubassets.com/7332ebd407d3e17f68ad89bb637cf6a8aec3ae71dc4df677641ee3f650e3260a/python/cpython/issues/133509 og:image:alt Bug report Bug description: Hi, since #131802, we see test_peg_generator failing with the following warning: Warning -- logging._handlerList was modified by test_peg_generator Warning -- Before: (1... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username kulikjak hostname github.com expected-hostname github.com None b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb turbo-cache-control no-preview go-import github.com/python/cpython git https://github.com/python/cpython.git octolytics-dimension-user_id 1525981 octolytics-dimension-user_login python octolytics-dimension-repository_id 81598961 octolytics-dimension-repository_nwo python/cpython octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 81598961 octolytics-dimension-repository_network_root_nwo python/cpython turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release 07a982c1d40157c619b364352b704c3ce66bb332 ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.