mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
Added mt_interact() -- multithreaded version of interact().
interact() automatically uses this on Windows (where the single-threaded version doesn't work).
This commit is contained in:
parent
db01ee0e22
commit
82eae9eaa7
1 changed files with 26 additions and 0 deletions
|
@ -376,6 +376,9 @@ class Telnet:
|
||||||
|
|
||||||
def interact(self):
|
def interact(self):
|
||||||
"""Interaction function, emulates a very dumb telnet client."""
|
"""Interaction function, emulates a very dumb telnet client."""
|
||||||
|
if sys.platform == "win32":
|
||||||
|
self.mt_interact()
|
||||||
|
return
|
||||||
while 1:
|
while 1:
|
||||||
rfd, wfd, xfd = select.select([self, sys.stdin], [], [])
|
rfd, wfd, xfd = select.select([self, sys.stdin], [], [])
|
||||||
if self in rfd:
|
if self in rfd:
|
||||||
|
@ -393,6 +396,29 @@ class Telnet:
|
||||||
break
|
break
|
||||||
self.write(line)
|
self.write(line)
|
||||||
|
|
||||||
|
def mt_interact(self):
|
||||||
|
"""Multithreaded version of interact()."""
|
||||||
|
import thread
|
||||||
|
thread.start_new_thread(self.listener, ())
|
||||||
|
while 1:
|
||||||
|
line = sys.stdin.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
self.write(line)
|
||||||
|
|
||||||
|
def listener(self):
|
||||||
|
"""Helper for mt_interact() -- this executes in the other thread."""
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
data = self.read_eager()
|
||||||
|
except EOFError:
|
||||||
|
print '*** Connection closed by remote host ***'
|
||||||
|
return
|
||||||
|
if data:
|
||||||
|
sys.stdout.write(data)
|
||||||
|
else:
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def expect(self, list, timeout=None):
|
def expect(self, list, timeout=None):
|
||||||
"""Read until one from a list of a regular expressions matches.
|
"""Read until one from a list of a regular expressions matches.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue