General code timer. Use it as a decorator or context manager, as such:
The code!
Tempfile
Yes you can use the tempfile module, and in most cases this is the right choice.
Sometimes you may not know when to delete the file and it may fall outside of any context management. Here is one solution.
It subclasses the path to the file itself. When that path goes out of scope (nobody is using the file anymore) it deletes the file.