Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Issue with debugpy and post portem debug hook in Python 3.12+

オープン
#1,970 コメント 2 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
devtools

調査の方向性

まず、提供された test.py の再現を Python 3.12 と debugpy で実行します。debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py の traceback、特に build_exception_info_response を調査し、pydevd.stop_on_unhandled_exception を通る postmortem フックを追跡します。スクリプトが内部の AttributeError を発生させずに、発生した ValueError を処理できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement

Hi! Decided to post it as a separate issue - perhaps it indicate some general problem in debugpy too.

There was a script to setup postmortem debugger that would start debugpy automatically. It worked fine, but in 3.12 stopped wokring. There's some internal error in debugpy - see the script and steps to reproduce it below.

Snippet from @fabioz worked really well for me, but it seems to break in Python 3.12.
Haven't investigated in details yet - any ideas for a workaround?

uv venv --python 3.12
.venv\Scripts\activate
uv pip install debugpy
python test.py
# 2.04s - Error getting exception type.
# Traceback (most recent call last):
#   File ".venv\Lib\site-packages\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 1550, in build_exception_info_response
#     stype = frames_list.exc_type.__qualname__
#             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# AttributeError: 'NoneType' object has no attribute '__qualname__'
# test.py
def test():
    for i in range(5):
        print("Hello, world!", i)
        if i == 3:
            raise ValueError("Test exception")

def setup_post_portem():
    import sys
    from types import TracebackType
    from typing import Any, Callable, Type

    def make_debugpy_excepthook() -> Callable[[Type[BaseException], BaseException, TracebackType], Any]:
        """
        Return an excepthook that will initialise debugpy and then call through to
        its exception handler.
        """
        import debugpy

        original_debugpy_excepthook = sys.excepthook

        def debugpy_excepthook(
            type_: Type[BaseException],
            value: BaseException,
            traceback: TracebackType,
        ) -> Any:
            """
            Callback called when an exception is hit and debugpy is enabled.
            """
            if not debugpy.is_client_connected():
                print("Exception thrown. Waiting for debugpy on port 5678.")
                debugpy.listen(5678)
                debugpy.wait_for_client()

            import pydevd
            import threading

            py_db = pydevd.get_global_debugger()
            thread = threading.current_thread()
            additional_info = py_db.set_additional_thread_info(thread)
            additional_info.is_tracing += 1
            try:
                arg = (type_, value, traceback)
                py_db.stop_on_unhandled_exception(py_db, thread, additional_info, arg)
            finally:
                additional_info.is_tracing -= 1
            original_debugpy_excepthook(type_, value, traceback)

        return debugpy_excepthook

    sys.excepthook = make_debugpy_excepthook()

if __name__ == "__main__":
    setup_post_portem()
    test()

Originally posted by @Andrej730 in #723

主要言語
Python
スター
2.5k
フォーク
205
平均マージ
1日 5時間
マージ済み PR(30日)
4

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/debugpy のほかの issue

microsoft/debugpy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。