Skip to content

[non-deterministic] is_client_connected() crashes with KeyError: '_pydevd_bundle.pydevd_comm_constants' #2020

Closed

Description

Before creating a new issue, please check the FAQ to see if your question is answered there.

Environment data

  • debugpy version: 1.8.20
  • OS and version: macOS 26.3 + uv / .venv
  • Python version: 3.13
  • Using Cursor

Actual behavior

Crash during parallel testing on github runner (using pytest xdist) - the code calls:

is_client_connected()

Backtrace:

../../../.venv/lib/python3.13/site-packages/debugpy/public_api.py:44: in wrapper
    from debugpy.server import api
../../../.venv/lib/python3.13/site-packages/debugpy/server/__init__.py:7: in <module>
    import debugpy._vendored.force_pydevd  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/force_pydevd.py:44: in <module>
    preimport('pydevd', [
../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/__init__.py:126: in preimport
    import_module(name)
/home/runner/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/pydevd/pydevd.py:39: in <module>
    import pydevd_file_utils
../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/pydevd/pydevd_file_utils.py:47: in <module>
    from _pydevd_bundle.pydevd_comm_constants import file_system_encoding, filesystem_encoding_is_utf8
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

spec = ModuleSpec(name='_pydevd_bundle.pydevd_comm_constants', loader=<_frozen_importlib_external.SourceFileLoader object at ...venv/lib/python3.13/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm_constants.py')

>   ???
E   KeyError: '_pydevd_bundle.pydevd_comm_constants'

<frozen importlib._bootstrap>:946: KeyError

Expected behavior

No crash.

Steps to reproduce:

Unable to reproduce.

Activity

  1. rchiodo commented on Apr 29, 2026

    @rchiodo
    Contributor

    Thanks for the issue. Without a reproduction it'd be hard to diagnose though. The callstack doesn't make much sense to me. How can the loader have a key error?

  2. francescomikulis commented on May 5, 2026

    @francescomikulis
    Author

    Unfortunately the setup to reproduce this is complex.
    I'm using pytest-xdist with async tests.
    A function I call during the test, within an async context, and potentially many times in parallel (one per process) is:

    debugpy_is_client_connected()
    

    I'm using a .venv generated by uv.

    Also, this just happened again, this time with a different key error:

    ..[my private code]..
        and not debugpy_is_client_connected()
    ../../../.venv/lib/python3.13/site-packages/debugpy/public_api.py:44: in wrapper
        from debugpy.server import api
    ../../../.venv/lib/python3.13/site-packages/debugpy/server/__init__.py:7: in <module>
        import debugpy._vendored.force_pydevd  # noqa
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/force_pydevd.py:44: in <module>
        preimport('pydevd', [
    ../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/__init__.py:126: in preimport
        import_module(name)
    /home/runner/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13/importlib/__init__.py:88: in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ../../../.venv/lib/python3.13/site-packages/debugpy/_vendored/pydevd/pydevd.py:51: in <module>
        from _pydev_bundle.pydev_console_utils import DebugConsoleStdIn
    <frozen importlib._bootstrap>:1360: in _find_and_load
        ???
    <frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
        ???
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    spec = ModuleSpec(name='_pydev_bundle.pydev_console_utils', loader=<_frozen_importlib_external.SourceFileLoader object at ../.venv/lib/python3.13/site-packages/debugpy/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py')
    
    >   ???
    E   KeyError: '_pydev_bundle.pydev_console_utils'
    
    <frozen importlib._bootstrap>:946: KeyError
  3. francescomikulis commented on May 5, 2026

    @francescomikulis
    Author

    Unfortunately the setup to reproduce this is complex.
    I'm using pytest-xdist with async tests.
    A function I call during the test, within an async context, and potentially many times in parallel (one per process) is:
    debugpy_is_client_connected()
    I'm using a .venv generated by uv.

    Rich Chiodo (@rchiodo) is the above enough background?

  4. rchiodo commented on May 5, 2026

    @rchiodo
    Contributor

    I'd need tests that reproduce it. That's not enough for me to figure out where the problem is. Otherwise my guess is that the debugpy module is getting loaded from the wrong path and it can't find the matching pydevd.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions