From 48b9ea3cb004abc803aa232143e2cda72a9e1f3d Mon Sep 17 00:00:00 2001 From: Georgi Kolev Date: Thu, 3 Nov 2016 09:51:54 +0200 Subject: [PATCH] Fixing unhandled python2 socket exception --- ChangeLog.creole | 6 ++++++ ping.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog.creole b/ChangeLog.creole index 54bf936..be98204 100644 --- a/ChangeLog.creole +++ b/ChangeLog.creole @@ -1,5 +1,11 @@ == Revision history == +==== November 3, 2016 ==== +---------------- + * Adding exception when sending packets to handle socket.error (Python2.x issue) + Thanks to Ariana Giroux https://github.com/l4m3rx/python-ping/issues/16 + * Fixing MyStats printing. + ==== November 2, 2016 ==== ---------------- * Fix. Replacing print() with print('') to avoid python2.x printing "()" liens diff --git a/ping.py b/ping.py index 6e9d455..5f36218 100755 --- a/ping.py +++ b/ping.py @@ -236,6 +236,9 @@ def _send(mySocket, destIP, myID, mySeqNumber, numDataBytes, ipv6=False): except OSError as e: print("General failure (%s)" % str(e)) return + except socket.error as e: + print("General failure (%s)" % str(e)) + return return sendTime @@ -296,7 +299,7 @@ def _dump_stats(myStats): % (myStats.pktsSent, myStats.pktsRcvd, 100.0 * myStats.fracLoss)) if myStats.pktsRcvd > 0: - print("round-trip (ms) min/avg/max = %d/%0.1f/%d" % ( + print("round-trip (ms) min/avg/max = %0.1f/%0.1f/%0.1f" % ( myStats.minTime, myStats.totTime/myStats.pktsRcvd, myStats.maxTime ))