Thursday, 28 January 2021

Is there a way to check what part of my code leaves file handles open

Is there a way to track the python process to check where a file is being opened. I have too many files open when I use lsof on my running process but I'm not sure where they are being opened.

ls /proc/$pid/fd/ | wc -l

I suspect one of the libraries I'm using might have not handled the files properly. Is there a way to isolate exactly which line in my python code the files are being opened?

In my code I work with 3rd party libraries to process thousands of media files and since they are being left open I receive the error

OSError: [Errno 24] Too many open files

after running for a few minutes. Now I know raising the limit of open files is an option but this will just push the error to a later point of time.



from Is there a way to check what part of my code leaves file handles open

No comments:

Post a Comment