By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,932 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,932 IT Pros & Developers. It's quick & easy.

pexpect question....

P: n/a
Hi,

I am using pexpect to spawn an interactive program and wait for
particular string in its output. It works fine but once I get this
required information, I really don't care about the child process
anymore. I would effectively want to "detach" from it. Is there any way
to do such thing in pexpect? I did read pexpect's doc but couldn't find
any information in this regard. Currently, I am spawning a new thread
that just does pexpect_spawned_child.close(wait=1). It seems to work in
some cases but the child process is occassionally getting deadlocked.

# strace -p 23159
Process 23159 attached - interrupt to quit
write(2, "H_235J Task 4 being run as INCR"..., 72 <unfinished ...>

It just sits there indefinitely. Python is 2.3.3 and the OS is SuSe
9.1.

Thanks,
Raghu.

Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>>>>> "draghuram@gmail" == draghuram@gmail com <dr*******@gmail.com> writes:
Hi,
I am using pexpect to spawn an interactive program and wait for
particular string in its output. It works fine but once I get this
required information, I really don't care about the child process
anymore. I would effectively want to "detach" from it.


How about just calling close(), i.e. without wait=1? No need to spawn a new
thread.

Ganesan

--
Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA
Web: http://employees.org/~rganesan | http://rganesan.blogspot.com

Jul 19 '05 #2

P: n/a

Hi,

I actually replied saying that the process dies when close(wait=0) is
done (the reply doesn't show up yet). It is not correct. The process
actually runs but ends up in zombie status (defunct).

Raghu.

Jul 21 '05 #3

P: n/a
dr*******@gmail.com wrote:
Currently, I am spawning a new thread
that just does pexpect_spawned_child.close(wait=1). It seems to work in
some cases but the child process is occassionally getting deadlocked.


I think your only cross-platform option will be to fix the child
process to die nicely instead of trying to find better ways kill it.

-Jonathan

Jul 21 '05 #4

P: n/a

Hi,

While I continue to look at the problem, I thought I would post more
details. In a sense, this is more of a UNIX issue.

I have a python script that uses pexpect to spawn a child process (p1).
The python script then goes ahead and does a "tail --pid=p1". Assuming
that I do close(wait=0), P1 completes and gets stuck in zombie status.
The python script is also stuck because "tail" will not return until
zombie P1 goes away. So each is waiting for the other to go away
resulting in a deadlock.

Apparently, when close(wait=0) is done, all that pexpect does is that
it wouldn't call wait() on the spawned process anymore. I was looking
for a solution where pexpect also should be able to tell kernel that it
doesn't care about child process's exit status. Note that this is
different from not doing "wait". I think this can be achieved by
ignoring SIGCLD on SVR4 systems but I am not sure what is the
(expected) behaviour on posix/linux. Unfortunately, only parent process
can control this behaviour. So my questions are two fold.

1) What is the best way (preferably a generic UNIX way) for a parent
process to inform kernel that it is not interested in child process's
exit status?

2) How can this be achieved in pexpect module since it is spawning the
child process in my case.

As I said, this is more of a UNIX question rather than python one.

Thanks,
Raghu.

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.