global
statement detected PYL-W0603 74
75
76def recordMetrics():
77 global lastUsage 78 global prior_stats
79 myStats = stats.copy()
80 myPriorStats = {}
75
76def recordMetrics():
77 global lastUsage
78 global prior_stats 79 myStats = stats.copy()
80 myPriorStats = {}
81 stats.clear()
47
48
49def getCpuUsage():
50 global lastUsage, lastUsageTime 51
52 rusage = getrusage(RUSAGE_SELF)
53 currentUsage = rusage.ru_utime + rusage.ru_stime
220
221
222def reloadStorageSchemas():
223 global SCHEMAS224 try:
225 SCHEMAS = loadStorageSchemas()
226 except Exception as e:
228
229
230def reloadAggregationSchemas():
231 global AGGREGATION_SCHEMAS232 try:
233 AGGREGATION_SCHEMAS = loadAggregationSchemas()
234 except Exception as e:
It is recommended not to use global
statement unless it is really necessary. Global variables are dangerous because they can be simultaneously accessed from multiple sections of a program. This frequently results in bugs. This also make code difficult to read, because they force you to search through multiple functions or even modules just to understand all the different locations where the global variable is used and modified. Read more about why it should be avoided here.