There is the following code:
child = pexpect.spawn("prog")
#some delay...
child.expect(Name .*: )
child.sendline('anonymous')
When the child process has been launched it can start to send to its stdout a lot of data e.g. log info. Does it mean pexpect start to look up through all child's stdout (from the start of process to the current moment)? Or pexpect starts to do it after expect
calling only?
My child process makes a lot of log info. And CPU's going very slow. I suppose such pexpect's implementation can be cause
After a child process is spawned, the child will
write()
its data to the pty (slave side) and waiting for the parent toread()
the data from the pty (master side). If there's nochild.expect()
the child'swrite()
may be blocked when it's outputing too much data because the write buffer is full.When
child.expect()
matches a pattern it'll return and then you have to callchild.expect()
again otherwise the child may still be blocked after it outputs too much data.See following example:
At this time the
find
is spawned and it's already outputted some data. But I did not callch.expect()
so thefind
is now being blocked (sleeping) and it does not consume CPU.Here the STAT
S
means sleeping (ands
means session leader,+
means foreground process).According to pexpect's document, two options of spawn() may affect performance: