This can be implemented using the `signal` module in the python standard library. If you agree that this could be useful I will work on a pull request.