0

I'm looking for way to delete secure files if a program were to crash in any way. Is there a way to do this in python?

I've been looking at the tempfile module to see if this were possible. Looking it over, I believe it is not suitable. I think it needs to explicitly close a file to delete it.

4
  • What are you trying to do? Someone may access the files before your code finishes. (Only some file systems support locking.) Usually the file permissions for any such files would be set that only the owner can read them. That said, you could write a watchdog program that check whether the main one is still alive and then either cleans up or restarts it. Commented Apr 13, 2023 at 19:43
  • 1. You could have a second program that monitors the first program and deletes the file when it closes. 2. you could store the files in memory and write it to disk only if the program exits securely. 3. You could use an encrypted file with the keys only existing in memory. Commented Apr 13, 2023 at 19:54
  • The best way is to delete the file after you open it. When the program closes the file or exits, the file will go away. If the file is being used for communication between processes, delete it after all the processes open it. Commented Apr 13, 2023 at 20:05
  • If the application is written in python, you could register an exit handler to delete the files. This would handle any "normal" exit, including python level exceptions. But wouldn't handle something like a segfault in a C extension. Commented Apr 13, 2023 at 21:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.