graphite-project / carbon

File opened without the with statement PTC-W0010
Anti-pattern
Critical
4 years ago4 years old
Use the with statement to open a file
408
409        elif action == "start":
410            if exists(pidfile):
411                pf = open(pidfile, 'r')412                try:
413                    pid = int(pf.read().strip())
414                    pf.close()
Use the with statement to open a file
381            if not exists(pidfile):
382                print("%s (instance %s) is not running" % (program, instance))
383                raise SystemExit(1)
384            pf = open(pidfile, "r")385            try:
386                pid = int(pf.read().strip())
387                pf.close()
Use the with statement to open a file
350            if not exists(pidfile):
351                print("Pidfile %s does not exist" % pidfile)
352                raise SystemExit(0)
353            pf = open(pidfile, 'r')354            try:
355                pid = int(pf.read().strip())
356                pf.close()
Use the with statement to open a file
32    For more details, "man proc" and "man uptime"
33    """
34    if platform.system() == "Linux":
35        return open('/proc/loadavg').read().split()[:3]36    else:
37        command = "uptime"
38        process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
Use the with statement to open a file
30    For more details, "man proc" and "man uptime"
31    """
32    if platform.system() == "Linux":
33        return open('/proc/loadavg').read().split()[:3]34    else:
35        command = "uptime"
36        process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)