1

Somewhere in my program, I get a ResourceWarning saying that a file handle has been deleted that did not call close(). However, I am in a giant project and cannot easily find the file handle.

How can I use the gc library to log the name of the file handle's file, or the name of the file in which I create the file handle?

Btw, I am sure the problem has to do with garbage collection, because if I prefix my script with gc.disable(), I don't see the warning.

Update: I only see the Warning log when I run from the context of unittest.main().

Jonathan Allen Grant
  • 3,408
  • 6
  • 30
  • 53

0 Answers0