Skip to content

Commit 148b86e

Browse files
author
Martin Walsh
committed
deepcopy dicts to avoid passing around references
1 parent 607af5e commit 148b86e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

network/netstats/python_modules/netstats.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import re
33
import time
4+
import copy
45

56
PARAMS = {}
67

@@ -13,7 +14,7 @@
1314
tcpext_file = "/proc/net/netstat"
1415
snmp_file = "/proc/net/snmp"
1516

16-
LAST_METRICS = dict(METRICS)
17+
LAST_METRICS = copy.deepcopy(METRICS)
1718
METRICS_CACHE_MAX = 5
1819

1920
stats_pos = {}
@@ -188,10 +189,10 @@ def get_metrics():
188189
if re.match("TcpExt: [0-9]", line):
189190
metrics = re.split("\s+", line)
190191

191-
file.close
192+
file.close()
192193

193194
# update cache
194-
LAST_METRICS = dict(METRICS)
195+
LAST_METRICS = copy.deepcopy(METRICS)
195196
METRICS = {
196197
'time': time.time(),
197198
'tcpext': metrics
@@ -216,7 +217,7 @@ def get_metrics():
216217
METRICS['tcp'] = re.split("\s+", line)
217218

218219

219-
file.close
220+
file.close()
220221

221222
return [METRICS, LAST_METRICS]
222223

0 commit comments

Comments
 (0)