diff options
author | Guido van Rossum <guido@python.org> | 1998-12-23 23:04:17 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-12-23 23:04:17 +0000 |
commit | 8fbde7829445e4a87c257dce769c5070a9f4b6b1 (patch) | |
tree | 5966147df9a7f1c56ad64c4e30a396026e04f215 /Lib/telnetlib.py | |
parent | e956c0657271d7f4158fde538f389f809184d780 (diff) | |
download | cpython-8fbde7829445e4a87c257dce769c5070a9f4b6b1.tar.gz |
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/telnetlib.py')
-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 8cf372e3f9..efb2b4059c 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. |