From 98c7d93491625828dcd69dede151f4342ea333ab Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Wed, 14 Oct 2015 10:39:14 -0700 Subject: Add new spawn.delayafterread attribute. --- pexpect/expect.py | 5 +++-- pexpect/spawnbase.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pexpect/expect.py b/pexpect/expect.py index 6fde9e8..1c7a163 100644 --- a/pexpect/expect.py +++ b/pexpect/expect.py @@ -95,7 +95,8 @@ class Expecter(object): return self.timeout() # Still have time left, so read more data incoming = spawn.read_nonblocking(spawn.maxread, timeout) - time.sleep(0.0001) + if self.spawn.delayafterread is not None: + time.sleep(self.spawn.delayafterread) if timeout is not None: timeout = end_time - time.time() except EOF as e: @@ -294,4 +295,4 @@ class searcher_re(object): self.start = first_match self.match = the_match self.end = self.match.end() - return best_index \ No newline at end of file + return best_index diff --git a/pexpect/spawnbase.py b/pexpect/spawnbase.py index 0518d83..4664884 100644 --- a/pexpect/spawnbase.py +++ b/pexpect/spawnbase.py @@ -70,6 +70,10 @@ class SpawnBase(object): # Used by terminate() to give kernel time to update process status. # Time in seconds. self.delayafterterminate = 0.1 + # After each call to read_nonblocking(), pexpect releases the GIL + # through a time.sleep(0.0001) call by default since version 2.1. + # When set as value 'None', the old 2.0 behavior is restored. + self.delayafterread = 0.0001 self.softspace = False self.name = '<' + repr(self) + '>' self.closed = True -- cgit v1.2.1