diff options
author | Thomas Kluyver <takowl@gmail.com> | 2016-01-06 14:51:48 +0000 |
---|---|---|
committer | Thomas Kluyver <takowl@gmail.com> | 2016-01-06 14:51:48 +0000 |
commit | 524495960dd8898ddd30f7ba37298de51beee773 (patch) | |
tree | 06576b536657ca55ebfaedd3fc66a7be3b50affc | |
parent | 4a2128a00d42dc0ce90cb7cac00d0b7278a23531 (diff) | |
parent | 470ab3c57d5b619149e817d9e8e10a0148711c64 (diff) | |
download | pexpect-524495960dd8898ddd30f7ba37298de51beee773.tar.gz |
Merge pull request #313 from jdemeyer/delayafterread
Add new ``delayafterread`` class attribute, for removing Superfluous sleep
-rw-r--r-- | pexpect/expect.py | 5 | ||||
-rw-r--r-- | pexpect/spawnbase.py | 8 | ||||
-rw-r--r-- | tests/test_delay.py | 18 | ||||
-rwxr-xr-x | tests/test_expect.py | 2 |
4 files changed, 29 insertions, 4 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..5dd24b5 100644 --- a/pexpect/spawnbase.py +++ b/pexpect/spawnbase.py @@ -62,7 +62,7 @@ class SpawnBase(object): # Data before searchwindowsize point is preserved, but not searched. self.searchwindowsize = searchwindowsize # Delay used before sending data to child. Time in seconds. - # Most Linux machines don't like this to be below 0.03 (30 ms). + # Set this to None to skip the time.sleep() call completely. self.delaybeforesend = 0.05 # Used by close() to give kernel time to update process status. # Time in seconds. @@ -70,6 +70,12 @@ class SpawnBase(object): # Used by terminate() to give kernel time to update process status. # Time in seconds. self.delayafterterminate = 0.1 + # Delay in seconds to sleep after each call to read_nonblocking(). + # Set this to None to skip the time.sleep() call completely: that + # would restore the behavior from pexpect-2.0 (for performance + # reasons or because you don't want to release Python's global + # interpreter lock). + self.delayafterread = 0.0001 self.softspace = False self.name = '<' + repr(self) + '>' self.closed = True diff --git a/tests/test_delay.py b/tests/test_delay.py index 8674336..1e4dba6 100644 --- a/tests/test_delay.py +++ b/tests/test_delay.py @@ -25,3 +25,21 @@ class TestCaseDelay(PexpectTestCase.PexpectTestCase): p.delaybeforesend = None p.sendline("line 3") p.expect("line 3") + + def test_delayafterread(self): + """ + Test various values for delayafterread. + """ + p = pexpect.spawn("cat") + + p.delayafterread = 1 + p.sendline("line 1") + p.expect("line 1") + + p.delayafterread = 0.0 + p.sendline("line 2") + p.expect("line 2") + + p.delayafterread = None + p.sendline("line 3") + p.expect("line 3") diff --git a/tests/test_expect.py b/tests/test_expect.py index 3f4c9d8..dcf059b 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -433,7 +433,7 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): self._before_after(p) def _ordering(self, p): - p.timeout = 5 + p.timeout = 20 p.expect(b'>>> ') p.sendline('list(range(4*3))') |