summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2003-05-17 06:32:00 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2003-05-17 06:32:00 +0000
commit7aaddfdc213683eca5422f839ac4d9b06233a484 (patch)
tree20b5a3abb314f1a9c37e74434062c5e2d6d818f7
parent6722e50ac843474e0dba698697b6d34579af6c95 (diff)
downloadpexpect-7aaddfdc213683eca5422f839ac4d9b06233a484.tar.gz
Added option to waitpid on close()
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@202 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/pexpect.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index 3a88aa4..03504a6 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -214,20 +214,27 @@ class spawn:
"""This returns the file descriptor of the pty for the child."""
return self.child_fd
- def close (self): # File-like object.
+ def close (self, wait=1): # File-like object.
""" This closes the connection with the child application.
It makes no attempt to actually kill the child or wait for its status.
If the file descriptor was set by passing a file descriptor
to the constructor then this method raises an exception.
Note that calling close() more than once is valid.
This emulates standard Python behavior with files.
+ If wait is set to True then close will wait
+ for the exit status of the process. This is a blocking call,
+ but this usually takes almost no time at all. If you are
+ creating lots of children then you usually want to call wait.
+ Only set wait to false if yo uknow the child will
+ continue to run after closing the controlling TTY.
"""
if self.child_fd != -1:
if not self.__child_fd_owner:
raise ExceptionPexpect ('This file descriptor cannot be closed because it was not created by spawn. The original creator is responsible for closing it.')
self.flush()
os.close (self.child_fd)
- os.waitpid (self.pid, 0)
+ if wait:
+ os.waitpid (self.pid, 0)
self.child_fd = -1
self.__child_fd_owner = None