aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-02-17 07:59:03 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-02-17 07:59:03 +0100
commitdecb3bc8de23e0586a4eb067fda74b0091e65393 (patch)
treeb0e59f98a1168d82d8a78841b06f52ead43b670f /source
parentUpdated comments. (diff)
downloadnewspipe-decb3bc8de23e0586a4eb067fda74b0091e65393.tar.gz
newspipe-decb3bc8de23e0586a4eb067fda74b0091e65393.tar.bz2
newspipe-decb3bc8de23e0586a4eb067fda74b0091e65393.zip
Improved writepid and pidof functions.
Diffstat (limited to 'source')
-rwxr-xr-xsource/pyAggr3g470r18
1 files changed, 7 insertions, 11 deletions
diff --git a/source/pyAggr3g470r b/source/pyAggr3g470r
index 3ea48933..a231a181 100755
--- a/source/pyAggr3g470r
+++ b/source/pyAggr3g470r
@@ -54,11 +54,9 @@ def writepid(processname = None, pid = None):
"""
pidpath = os.path.join(PATH, "var", processname + ".pid")
if processname is not None and pid is not None:
- f = open (pidpath, "w")
- f.write(str(pid))
- f.close()
- return True
- else:
+ with open(pidpath, "w") as f:
+ f.write(str(pid))
+ return True
return False
def checkpid (servicename = None):
@@ -71,11 +69,9 @@ def checkpid (servicename = None):
def pidof(processname = None):
pidpath = os.path.join(PATH, "var", processname + ".pid")
if processname is not None and os.path.exists(pidpath):
- f = open (pidpath)
- pid = f.read()
- f.close()
- return pid
- else:
+ with open(pidpath) as f:
+ pid = f.read()
+ return pid
return False
def rmpid (processname = None):
@@ -93,7 +89,7 @@ def start(python_command):
print(SERVICE + " is starting with pid: " + pidof(processname=SERVICE))
else:
print(SERVICE + " could not be started (pid exists)")
- retval=False
+ retval = False
def stop():
print("Stopping pyAggr3g470r...")
bgstack15