From fbfaace43b953bdf94c149367c36cb8abf52fd9a Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Tue, 7 Oct 2003 12:27:15 +0000 Subject: [PATCH] Print how fast sunet and funet are to respond. Handle timeout errors, since they are sometimes very slow. --- demo/dualftp.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/demo/dualftp.py b/demo/dualftp.py index e6a54c2..e2cff3e 100644 --- a/demo/dualftp.py +++ b/demo/dualftp.py @@ -6,10 +6,14 @@ # # This also tests the expect_after functionality. +import sys +import time + import pcl_expect pcl_expect.stty_init = "-onlcr -ocrnl -echo" +time0 = time.time() funet = pcl_expect.spawn("ftp ftp.funet.fi") sunet = pcl_expect.spawn("ftp ftp.sunet.se") @@ -25,6 +29,8 @@ cmds = {} cmds[funet] = ["cd pub\n", "passive\n", "dir\n"] cmds[sunet] = ["cd pub\n", "passive\n", "dir\n"] +speed = {} + printed = 0 def prompt_cb(ftp): global printed @@ -35,6 +41,7 @@ def prompt_cb(ftp): else: print ftp.match.group() printed += 1 + speed[ftp] = time.time() - time0 pcl_expect.debug("STATE: cmds[sunet] = %s\n" % cmds[sunet]) pcl_expect.debug("STATE: cmds[funet] = %s\n" % cmds[funet]) @@ -51,7 +58,11 @@ pcl_expect.expect_after([(pcl_expect.RE, funet, "Name.*:", name_cb), x = pcl_expect.impl() while x.loop(): - pass + if x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue sunet.send("bye\n") funet.send("bye\n") @@ -63,9 +74,22 @@ while x.loop(): if x.eof(sunet): print "SUNET final output:", sunet.match sunet.close() + elif x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue x = pcl_expect.impl() while x.loop(): if x.eof(funet): print "FUNET final output:", funet.match funet.close() + elif x.timeout(): + sys.stdout.write(".") + sys.stdout.flush() + x.cont() + continue + +print "SUNET time:", speed[sunet], "seconds" +print "FUNET time:", speed[funet], "seconds" -- GitLab