summaryrefslogtreecommitdiffstats
path: root/0001-Stop-asyncio-listening-to-pty-once-we-ve-found-what-.patch
blob: b84b4ce58ffe925d458ad584941821c85f61e556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 5e6e0ad21acfed32c57ae8ef23a8a0722869afe1 Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <takowl@gmail.com>
Date: Tue, 13 Oct 2015 12:41:09 +0100
Subject: [PATCH] Stop asyncio listening to pty once we've found what we need

Closes gh-213 (fingers crossed)
---
 pexpect/async.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pexpect/async.py b/pexpect/async.py
index a798457..136fc0e 100644
--- a/pexpect/async.py
+++ b/pexpect/async.py
@@ -23,6 +23,7 @@ def expect_async(expecter, timeout=None):
         return expecter.timeout(e)
 
 class PatternWaiter(asyncio.Protocol):
+    transport = None
     def __init__(self, expecter):
         self.expecter = expecter
         self.fut = asyncio.Future()
@@ -30,10 +31,15 @@ class PatternWaiter(asyncio.Protocol):
     def found(self, result):
         if not self.fut.done():
             self.fut.set_result(result)
+            self.transport.pause_reading()
     
     def error(self, exc):
         if not self.fut.done():
             self.fut.set_exception(exc)
+            self.transport.pause_reading()
+
+    def connection_made(self, transport):
+        self.transport = transport
     
     def data_received(self, data):
         spawn = self.expecter.spawn
-- 
2.6.1