From 44faa66789920bf0951f23717a98f030279a5e08 Mon Sep 17 00:00:00 2001 From: Valentyn Tymofieiev Date: Wed, 12 Feb 2025 13:40:27 +0100 Subject: [PATCH 1/3] Work around https://github.com/python/cpython/issues/106883 --- .../apache_beam/runners/worker/worker_status.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/runners/worker/worker_status.py b/sdks/python/apache_beam/runners/worker/worker_status.py index ecd4dc4e02c0..186453ffd375 100644 --- a/sdks/python/apache_beam/runners/worker/worker_status.py +++ b/sdks/python/apache_beam/runners/worker/worker_status.py @@ -17,6 +17,7 @@ """Worker status api handler for reporting SDK harness debug info.""" +import gc import logging import queue import sys @@ -53,11 +54,23 @@ LOG_LULL_FULL_THREAD_DUMP_LULL_S = 20 * 60 +def _current_frames(): + # Work around https://github.com/python/cpython/issues/106883 + if (sys.version_info.minor == 11 and sys.version_info.major == 3 and + gc.isenabled()): + gc.disable() + frames = sys._current_frames() # pylint: disable=protected-access + gc.enable() + return frames + else: + return sys._current_frames() # pylint: disable=protected-access + + def thread_dump(): """Get a thread dump for the current SDK worker harness. """ # deduplicate threads with same stack trace stack_traces = defaultdict(list) - frames = sys._current_frames() # pylint: disable=protected-access + frames = _current_frames() for t in threading.enumerate(): try: @@ -269,7 +282,7 @@ def _log_lull_sampler_info(self, sampler_info, instruction): def _get_stack_trace(self, sampler_info): exec_thread = getattr(sampler_info, 'tracked_thread', None) if exec_thread is not None: - thread_frame = sys._current_frames().get(exec_thread.ident) # pylint: disable=protected-access + thread_frame = _current_frames().get(exec_thread.ident) return '\n'.join( traceback.format_stack(thread_frame)) if thread_frame else '' else: From 2f24213dbb235dd3b29c683cf46e5afade1611fd Mon Sep 17 00:00:00 2001 From: Valentyn Tymofieiev Date: Wed, 12 Feb 2025 14:30:02 +0100 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index fc4a32120afa..81d9e9daf31e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -78,7 +78,7 @@ ## Bugfixes -* Fixed X (Java/Python) ([#X](https://github.com/apache/beam/issues/X)). +* (Python) Fixed occassional stuckness of Beam jobs that affected users of Python 3.11 ([#33966](https://github.com/apache/beam/issues/33966)). ## Security Fixes * Fixed (CVE-YYYY-NNNN)[https://www.cve.org/CVERecord?id=CVE-YYYY-NNNN] (Java/Python/Go) ([#X](https://github.com/apache/beam/issues/X)). From 9325c0c82cdc288acfd23ce204f48b6417102cf9 Mon Sep 17 00:00:00 2001 From: tvalentyn Date: Wed, 12 Feb 2025 19:38:43 +0100 Subject: [PATCH 3/3] Grammar --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 81d9e9daf31e..8b43d6e73e04 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -78,7 +78,7 @@ ## Bugfixes -* (Python) Fixed occassional stuckness of Beam jobs that affected users of Python 3.11 ([#33966](https://github.com/apache/beam/issues/33966)). +* (Python) Fixed occasional pipeline stuckness that was affecting Python 3.11 users ([#33966](https://github.com/apache/beam/issues/33966)). ## Security Fixes * Fixed (CVE-YYYY-NNNN)[https://www.cve.org/CVERecord?id=CVE-YYYY-NNNN] (Java/Python/Go) ([#X](https://github.com/apache/beam/issues/X)).