Skip to main content

Rescuing data from abrubt process termination in python.

Project description


Build Status GitHub license pypi version

Rescuing data from abrubt process termination in Python3.


If a process experiences e.g. a segmentation fault, it cannot execute further operations to recover. Also, memory of a process is considered inconsistent after a segmentation fault. As soon as a project depends on third party libraries, the appearence of such faults is out of hand. Therefore, to implement a crash handler for important data, an approach to prepare for rescuing data after an abrupt process termination is needed. This module uses the Python modules 'pickle', 'multiprocessing' and 'collections', to serialize and deserialize various types of data and provides a dictory-like data type to save and recover important data in the adress space of an independent process.

This module is really simple, although its functionality is very reuseable. If you are versed in this topic, feel encouraged to look into the source code and to contribute through (well documented ;) ) pull requests.


This module is available through pip or can be installed manually via


This module is focused on projects that e.g. rely on native libraries and have important data. It will not provide you any help in fixing a segmentation fault and you should feel encouraged to learn about the Python module 'faulthandler' and the use of 'gdm' to fix faults in your own code. If you somehow manage to generate a segmentation fault in the faultguard data dictionary, and therefore destroy the guard process, the rescue will of course not work. This module is an additional security option, not an excuse for irresponsible programming!


It follows a minimal working example for this module:

import faultguard
import numpy as np

def launch(faultguard_data, args):
    Demo software main method
    :param faultguard_data: Faultguard data dictionary
    :param args: Data passed from faultguard.start.
    print("Launching demo")
    # Some important data
    important_data_1 = np.array([1,2,3])
    important_data_2 = args[0] + " " + args[1]
    # Some dummy important data manipulation
    for i in range(10):
        important_data_1[i%3] = i
        important_data_2 += str(i)
        print("important_data_1:", important_data_1)
        print("important_data_2:", important_data_2)
        # Sending important data to faultguard process
        faultguard_data["important_data_1"] = important_data_1
        faultguard_data["important_data_2"] = important_data_2
        # Generate segfault
        if i == 7:
            import ctypes
def rescue(faultguard_data, exit_code, args):
    Demo rescue handler
    :param faultguard_data: Faultguard data dictionary
    :param exit_code: Exit code of occured fault.
    :param args: Data passed from faultguard.start.
    print("Fault occured. Exit code: {}. Rescued data:".format(exit_code))
    # Check if fault occurs before data was initialized
    if "important_data_1" not in faultguard_data or "important_data_2" not in faultguard_data:
    # Restore data
    important_data_1 = faultguard_data["important_data_1"]
    important_data_2 = faultguard_data["important_data_2"]
    # You might need to assign the class here by important_data_1.__class__ = ...
    print("important_data_1:", important_data_1)
    print("important_data_2:", important_data_2)
def main():
    faultguard.start(launch, rescue, args=("Hello", "World"))

if __name__ == "__main__":


This project was initially developed for a hardware project at the University of Münster.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for faultguard, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size faultguard-1.0.2.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page