summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2015-12-14 11:58:33 +0100
committerThomas Kluyver <takowl@gmail.com>2015-12-14 11:58:33 +0100
commit07ca73ad72f20b026737a50136e8cd266f7ece49 (patch)
treef7b657268cd456894e95e76ef54dd993369dfefa
parent3451858cf0061aff06c8a82fdc628270336cbc8c (diff)
parent8410e6e6b708f1d78d4d155ce909cea13f428a2f (diff)
downloadpexpect-07ca73ad72f20b026737a50136e8cd266f7ece49.tar.gz
Merge pull request #307 from jdemeyer/none_delaybeforesend
Allow delaybeforesend=None to skip the sleep completely
-rw-r--r--doc/commonissues.rst2
-rw-r--r--pexpect/pty_spawn.py6
-rw-r--r--tests/test_delay.py27
3 files changed, 31 insertions, 4 deletions
diff --git a/doc/commonissues.rst b/doc/commonissues.rst
index d3aa9d0..f60085e 100644
--- a/doc/commonissues.rst
+++ b/doc/commonissues.rst
@@ -47,7 +47,7 @@ not be an issue for most users. For some applications you might with to turn it
off::
child = pexpect.spawn ("ssh user@example.com")
- child.delaybeforesend = 0
+ child.delaybeforesend = None
Truncated output just before child exits
----------------------------------------
diff --git a/pexpect/pty_spawn.py b/pexpect/pty_spawn.py
index 299016c..1e9a032 100644
--- a/pexpect/pty_spawn.py
+++ b/pexpect/pty_spawn.py
@@ -144,8 +144,7 @@ class spawn(SpawnBase):
many users that I decided that the default pexpect behavior should be
to sleep just before writing to the child application. 1/20th of a
second (50 ms) seems to be enough to clear up the problem. You can set
- delaybeforesend to 0 to return to the old behavior. Most Linux machines
- don't like this to be below 0.03. I don't know why.
+ delaybeforesend to None to return to the old behavior.
Note that spawn is clever about finding commands on your path.
It uses the same logic that "which" uses to find executables.
@@ -511,7 +510,8 @@ class spawn(SpawnBase):
>>> bash.sendline('x' * 5000)
'''
- time.sleep(self.delaybeforesend)
+ if self.delaybeforesend is not None:
+ time.sleep(self.delaybeforesend)
s = self._coerce_send_string(s)
self._log(s, 'send')
diff --git a/tests/test_delay.py b/tests/test_delay.py
new file mode 100644
index 0000000..8674336
--- /dev/null
+++ b/tests/test_delay.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+from . import PexpectTestCase
+import pexpect
+
+
+class TestCaseDelay(PexpectTestCase.PexpectTestCase):
+ """
+ Tests for various delay attributes.
+ """
+ def test_delaybeforesend(self):
+ """
+ Test various values for delaybeforesend.
+ """
+ p = pexpect.spawn("cat")
+
+ p.delaybeforesend = 1
+ p.sendline("line 1")
+ p.expect("line 1")
+
+ p.delaybeforesend = 0.0
+ p.sendline("line 2")
+ p.expect("line 2")
+
+ p.delaybeforesend = None
+ p.sendline("line 3")
+ p.expect("line 3")