pid = os.fork()
if pid == 0:
    os.setsid()
else:
    print('Waiting for ssh (pid %d)' % pid)
os.waitpid(pid, 0)
print('Done')
How to call ssh by subprocess module so that it uses SSH_ASKPASS variable