I'm developing a PyQt applications so there's a good possibility segfaults could happen.
I want to use the faulthandler module to catch these. Now instead of writing to stderr I want to do the following:
- Make faulthandler write into a file with a known location.
- When starting again (normally or after a crash), check if that file exists and has a crash log in it.
- If it does, open a dialog which asks the user to open a bug report with the crash log, then delete it.
Now this works fine, except when I run multiple instances of my application.
Then I thought I could write into a random file with a known location (say, crash-XXXXX.log
), and then when starting check for crash-*.log
, and if it's non-empty do the same thing as above.
However when doing it that way, at least on Linux I'll be able to delete the file while another instance might still have it open, and then if that instance crashes the log gets lost.
I also can't just open()
the file at the right time as faulthandler wants an open file.
I'm searching for a solution which:
- Works with multiple instances
- Catches crashes of all these instances correctly
- Only opens the crash dialog one time, when starting a new instance after one crashed.
- Doesn't leave any stale files behind after all instances are closed.
- Works at least on Linux and Windows
I've thought about some different approaches, but all of them have one of these drawbacks.