preexec_fn=os.setsid causes 'sudo: no tty present and no askpass program specified'

6 Jun 2017

I have no idea why… but I guess it's related to creating a new session. The below fails with sudo: no tty present and no askpass program specified:

import os import sys import subprocess proc = subprocess.Popen('sudo ls', shell=True, preexec_fn=os.setsid) print proc.communicate()