Skip to content

Commit

Permalink
Fixing unhandled python2 socket exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Kolev committed Nov 3, 2016
1 parent b25aa34 commit 48b9ea3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog.creole
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
))

Expand Down

0 comments on commit 48b9ea3

Please sign in to comment.