浏览代码

Return nan for transfer rate.

If the transfer rate cannot be calculated, return nan rather than raising a ZeroDivisionError exception.
Steven Engler 6 年之前
父节点
当前提交
421ea6d469
共有 1 个文件被更改,包括 5 次插入1 次删除
  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):