You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resource finalizer never called in VS Code debugger #158
Hi, I'm seeing some strange behaviour when attempting to use Resource type providers during debug sessions in VS Code. From adding both print statements and breakpoints into the code, it's clear that the code in the finally block is never reached when running in debug mode in VS Code. Running the code normally, i.e., as a python script in a terminal, I can see the print outputs as expected.
There is a minimal reproducible example below. In this case, it's not an issue; however the actual code where I noticed this problem launches a child process which must be terminated in the finally section (it runs an infinte loop - it's a message proxy). Failure to evaluate this finally block in VS Code debug mode causes test cases to run indefinitely. I can add similar code into a pytest conftest fixture and it works fine. It's worth mentioning that running the script inside VS Code but not in debug mode also works fine.
I'm running...
python: 3.12.8
that-depends: 1.27.0
vs code: 197.0
os: Windows 11 with WSL2 Ubuntu 24.04
# that_depends_example.pyimporttypingas_tfromthat_dependsimportBaseContainer, Provide, injectfromthat_depends.providersimportResourcedefsay_hello_goodbye() ->_t.Iterator[None]:
try:
print(f"Hello!")
yieldNonefinally:
print(f"Goodbye!")
classDI(BaseContainer):
"""`DI` is a dependency injection container for plugboard."""say_hello_goodbye: Resource[None] =Resource(say_hello_goodbye)
@injectdefrequire_resource(resource: None=Provide[DI.say_hello_goodbye]) ->None:
print("With resource...")
if__name__=="__main__":
require_resource()
Activity
lesnik512 commentedon Feb 11, 2025
@chrisk314 Hi!
In order to finalize resource you need to call DI.tear_down()
If you want to finalize after each call of require_resource, you can try using ContextResource