Browse Source

Return nan for transfer rate.

If the transfer rate cannot be calculated, return nan rather than raising a ZeroDivisionError exception.
Steven Engler 5 years ago
parent
commit
421ea6d469
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/basic_protocols.py

+ 5 - 1
src/basic_protocols.py

@@ -323,7 +323,11 @@ class PullDataProtocol(Protocol):
 	def calc_transfer_rate(self):
 		""" Returns bytes/s. """
 		assert self.data_size is not None and self.time_of_first_byte is not None and self.time_of_last_byte is not None
-		return self.data_size/(self.time_of_last_byte-self.time_of_first_byte)
+		try:
+			return self.data_size/(self.time_of_last_byte-self.time_of_first_byte)
+		except ZeroDivisionError:
+			return float('nan')
+		#
 	#
 #
 class SendDataProtocol(Protocol):