473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

pexpect question....

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
4 2278
>>>>> "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

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Surette | last post by:
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...
2
by: Adrian Casey | last post by:
I have a collection of tcl expect scripts which I am converting to python using the excellent pexpect module (http://pexpect.sourceforge.net/). So far I've had great success in getting all my...
3
by: Maurice LING | last post by:
I know this might sounds wierd but I'm wondering if I can use pexpect or os.popen3 function to invoke and control python interpreter to make it act like a python interpreter in python? maurice
0
by: Eric Myers | last post by:
Hello folks: (This message is also posted on the help forum at the pexpect sourceforge page, but all indentation in the code got stripped away when I submitted the post.) For some time I've...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
1
by: Kevin Erickson | last post by:
Hello, I am attempting to use pexpect in python to copy files from a server using scp; the copy works however exceptions are thrown and it exits unsuccessfully. Below is the a sample code and...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
1
by: Anh Khuong | last post by:
Hi all, I am using pexpect and I want to send output of pexpet to both stdout and log file concurrently. Anybody know a solution for it please let me know. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.