Skip to content

Commit

Permalink
Merge pull request #93 from martinwalsh/master
Browse files Browse the repository at this point in the history
deepcopy dicts to avoid passing around references
  • Loading branch information
vvuksan committed Oct 10, 2012
2 parents 607af5e + 148b86e commit f2a3f92
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions network/netstats/python_modules/netstats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import re
import time
import copy

PARAMS = {}

Expand All @@ -13,7 +14,7 @@
tcpext_file = "/proc/net/netstat"
snmp_file = "/proc/net/snmp"

LAST_METRICS = dict(METRICS)
LAST_METRICS = copy.deepcopy(METRICS)
METRICS_CACHE_MAX = 5

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

file.close
file.close()

# update cache
LAST_METRICS = dict(METRICS)
LAST_METRICS = copy.deepcopy(METRICS)
METRICS = {
'time': time.time(),
'tcpext': metrics
Expand All @@ -216,7 +217,7 @@ def get_metrics():
METRICS['tcp'] = re.split("\s+", line)


file.close
file.close()

return [METRICS, LAST_METRICS]

Expand Down

0 comments on commit f2a3f92

Please sign in to comment.