I'm coding a simple cross-platform file version-tracking program that's intended to open a single temp file with a given application, watch for modifications, and and stop watching and remove the file when process is done with it.
So far, I've had to dig into registry keys for Windows and desktop entries for Linux to find these apps, run them via subprocess.Popen and then watch for modifications using watchdog library. I realized then that different apps use different strategies to open/edit files, as some would lock the file (keep it open, such as for Microsoft Word), and other just copy it in memory and close the file immediately (such as VSCode or gedit). What I'm struggling with now is finding a general, or at least workable, way to code in Python that handles different apps, in different OS's.
What's the most efficient way to detect the end of watching?
Should I make it app-specific that at least handles more popular apps reliably?
Can OS help me? (I checked that
lsofwon't show open files ingedit, and I presumepids returned byPopenwon't always be helpful as apps that open files in tabs, and not windows, remain open if other tabs are open.)