Skip to content

Commit

Permalink
should avoid blocking time.sleep() in __del__
Browse files Browse the repository at this point in the history
Issue #20 is finally understood and closed by this
non-invasive fix -- although seemingly only occurring on
OSX, this call to to time.sleep() in __del__ is called at
regular intervals, especially more-so in python3 than
python2. Seemingly, only on OSX, this call to __del__
occurs mid-run during a call to spawn.expect_loop(),
causing either a TIMEOUT condition to occur, or an
exceptionally long blocking read (all the way up to
self.timeout), instead of the preferred EOF.
  • Loading branch information
jquast committed May 25, 2014
1 parent c4359ad commit 410835b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pexpect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,13 @@ def close(self, force=True):
if not self.closed:
self.flush()
os.close(self.child_fd)
# Give kernel time to update process status.
time.sleep(self.delayafterclose)
# Give kernel time to update process status before assertion
if self.isalive():
if not self.terminate(force):
time.sleep(self.delayafterclose)
if self.isalive() and not self.terminate(force):
raise ExceptionPexpect('Could not terminate the child.')
self.child_fd = -1
self.closed = True
#self.pid = None

def flush(self):
'''This does nothing. It is here to support the interface for a
Expand Down

0 comments on commit 410835b

Please sign in to comment.