close
Skip to content

Bug: Thread cleanup exception during interpreter shutdown when using VS Code debuggerΒ #2016

@indexedakki

Description

@indexedakki

πŸ“Œ Environment

  • Python Version: 3.13.5
  • OS: Windows 11
  • Debugger: VS Code (debugpy)

πŸ“ Description

When running code under the VS Code debugger, an exception is raised during interpreter shutdown:

Exception ignored in: <function _DeleteDummyThreadOnDel.__del__>
Traceback (most recent call last):
  File ".../threading.py", line 1385, in __del__
TypeError: 'NoneType' object does not support the context manager protocol

πŸ” Key Observation

  • ❌ Does NOT occur when running normally (python script.py)
  • βœ… Only occurs when running via VS Code debugger

πŸ§ͺ Steps to Reproduce

from strands import Agent, tool
from strands_tools import http_request
import boto3
from strands.models import BedrockModel

session = boto3.Session(region_name="us-east-1")

model = BedrockModel(
    model_id="your-model-id",
    boto_session=session
)

@tool
def dummy_tool(text: str) -> str:
    return text

agent = Agent(
    system_prompt="Test agent",
    tools=[http_request, dummy_tool],
    model=model
)

agent("Test request")

print("DONE EXECUTION")

πŸ“€ Observed Output (Debugger Only)

DONE EXECUTION
Exception ignored in: <function _DeleteDummyThreadOnDel.__del__>
Traceback (most recent call last):
  File ".../threading.py", line ...
TypeError: 'NoneType' object does not support the context manager protocol

βœ… Expected Behavior

No exception during interpreter shutdown in debugger mode.


❌ Actual Behavior

Thread cleanup triggers a TypeError during interpreter shutdown when running under debugger.


πŸ“Ž Notes

  • Likely related to debugger-managed threads and interpreter shutdown order
  • Possibly occurs when threads outlive global state during teardown
  • Does not impact runtime correctness

πŸ› οΈ Workarounds

  • Running script outside debugger avoids issue
  • Adding delays (time.sleep) reduces occurrence but does not fully eliminate

πŸ“Œ Summary

This appears to be a debugger-related threading cleanup issue during interpreter shutdown in Python 3.13.

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