start python program in the background that can prompt the user for password
Question: Basically I wanted to start a daemon in the background that will still prompt
the user in the console for a password. I created this with pexpect, but when
this program ends it kills the daemon since it is a child process. So
obviously pexpect isn't going to work for this. Does any body know of a way to
do this?

    
    
    #!/usr/bin/env python
    import pexpect
    import getpass
    child = pexpect.spawn('python daemon.py &')
    child.expect_exact('Password:')
    
    passwd = getpass.getpass()
    
    child.sendline(passwd)
    
    index = child.expect_exact('Started Successfully')
    print index
    


Answer: pexpect has a method [close(self,
force=True)](http://pexpect.sourceforge.net/pexpect.html#spawn-close) which
closes its connection to the child process.

According to the documentation, the child pocess is terminated if force=True
so

    
    
    child.close(force=False)
    

should disconnect, but leave the application running.

