import ctypes import os FUNC = ctypes.CFUNCTYPE(ctypes.c_int) def callback(): return 42 def do_stuff(): flist = [FUNC(callback) for i in range(100000)] for fn in flist: assert fn() == 42 pid = os.fork() # two processes from now on if pid == 0: # in the child process do_stuff() else: # in the parent process do_stuff() _, result = os.waitpid(pid, 0) if not os.WIFEXITED(result): print("child exited with signal %d" % os.WTERMSIG(result))