The fd:number code above will not work unmodified in modern versions of Python. You will have to call os.set_inheritable(r, True) to allow the openssl process to actually inherit the file descriptor.
fd:number
os.set_inheritable(r, True)