diff options
author | Guido van Rossum <guido@python.org> | 1998-12-23 23:04:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-12-23 23:04:17 (GMT) |
commit | 82eae9eaa70eb1f58277bd7d08b996507c3e3ffe (patch) | |
tree | cbc62d2ea889c3eb88bea44fbbdf26e50d7b8bb8 /Lib | |
parent | db01ee0e22c348b642143dbb728517ca7e13f526 (diff) | |
download | cpython-82eae9eaa70eb1f58277bd7d08b996507c3e3ffe.zip cpython-82eae9eaa70eb1f58277bd7d08b996507c3e3ffe.tar.gz cpython-82eae9eaa70eb1f58277bd7d08b996507c3e3ffe.tar.bz2 |
Added mt_interact() -- multithreaded version of interact().
interact() automatically uses this on Windows (where the
single-threaded version doesn't work).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/telnetlib.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py index 8cf372e..efb2b40 100644 --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -376,6 +376,9 @@ class Telnet: def interact(self): """Interaction function, emulates a very dumb telnet client.""" + if sys.platform == "win32": + self.mt_interact() + return while 1: rfd, wfd, xfd = select.select([self, sys.stdin], [], []) if self in rfd: @@ -393,6 +396,29 @@ class Telnet: break 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): """Read until one from a list of a regular expressions matches. |