msurette at laframboise.net
Wed Jan 28 15:33:04 CET 2004
On Wed, 28 Jan 2004 01:21:49 -0800, Manuel de Ferran wrote:
> Michael Surette <msurette at laframboise.net> wrote in message news:<pan.2004.01.26.22.07.43.147063 at laframboise.net>...
>> I have been trying to automate the changing of passwords using python and
>> pexpect. I wrote a script as a test and it works, except that it gives me
>> an exception when it stops running:
>> Exception exceptions.OSError:
>> (10, 'No child processes') in <bound method spawn.__del__ of
>> <pexpect.spawn instance at 0x403d938c>> ignored
>> What is happening and how do I get rid of the exception?
>> I am running python 2.3.2 under Slackware linux 9.1 and pexpect 0.99.
>> Here is the script:
>> import pexpect
>> import sys
>> if len(sys.argv) != 3:
>> print 'usage error!'
>> raise SystemExit
>> name= sys.argv
>> passwd= sys.argv
>> a= pexpect.spawn('passwd %s'%name)
>> changed= False
>> while not changed:
>> i= a.expect(['[Nn]ew password:','[Cc]hanged'])
>> if i == 0:
>> elif i == 1:
>> changed= True
> I have the same issue with the following code :
> #!/usr/bin/env python
> '''This runs "ls -l" on a remote host using SSH.
> At the prompts enter hostname, user, and password.
> import pexpect
> import getpass
> host = raw_input('Hostname: ')
> user = raw_input('User: ')
> password = getpass.getpass('Password: ')
> child = pexpect.spawn("ssh -l %s %s /bin/ls -l"%(user, host))
> print child.pid,'middle',child.isalive()
> print child.before
> This is a slighty modified version of sshls.py (shipped with
> pexpect-examples). I've only added "print
> and I get the same exception : "exceptions.OSError: (10, 'No child
> The weird thing I can't explain is that, I don't get the exception
> without ",child.alive()"
I have found a solution and an explanation.
Adding "a.close(False)" as a last line of my script fixes the problem.
The spawn.close() function calls os.pidwait() with your child process pid.
In our two cases, that pid is dead and os.pidwait rightfully raises an
exception. Calling spawn.close() with a False argument bypasses this
More information about the Python-list