def f(path): "one file object + forking" with lockpath.keeping(path) as file: if os.fork(): os.wait() else: lockfile(file)