aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2016-07-03 20:52:23 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2016-07-03 20:52:23 -0400
commit73ee9cb40f6539e9e70d41f7871ebefe929173a6 (patch)
tree738b35577ca83637a1fd58e272d41e373e8e29d1
parentdfa5855caada2ffca13b45ccf7242706f2ac35f6 (diff)
downloadsteuermann-73ee9cb40f6539e9e70d41f7871ebefe929173a6.tar.gz
Use "with" instead of direct "open"
-rw-r--r--steuermann/run.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/steuermann/run.py b/steuermann/run.py
index 48386ea..c90a40a 100644
--- a/steuermann/run.py
+++ b/steuermann/run.py
@@ -206,35 +206,35 @@ class runner(object):
raise
# open the log file, write initial notes
- logfile=open(logfile_name,"w")
- logfile.write('%s %s\n'%(datetime.datetime.now(),run))
- logfile.flush()
-
- # debug - just say the name of the node we would run
-
- if ( no_run ) :
- run = [ 'echo', 'disable run - node=', node.name ]
-
- # start running the process
- if debug :
- print("RUN",run)
- p = subprocess.Popen(
- args=run,
- stdout=logfile,
- stderr=subprocess.STDOUT,
- shell=False, close_fds=True
- )
+ with open(logfile_name,"w") as logfile:
+ logfile.write('%s %s\n'%(datetime.datetime.now(),run))
+ logfile.flush()
+
+ # debug - just say the name of the node we would run
+
+ if ( no_run ) :
+ run = [ 'echo', 'disable run - node=', node.name ]
+
+ # start running the process
+ if debug :
+ print("RUN",run)
+ p = subprocess.Popen(
+ args=run,
+ stdout=logfile,
+ stderr=subprocess.STDOUT,
+ shell=False, close_fds=True
+ )
- # remember the popen object for the process; remember the open log file
- n = struct()
- n.proc = p
- n.logfile = logfile
- n.logfile_name = logfile_name
+ # remember the popen object for the process; remember the open log file
+ n = struct()
+ n.proc = p
+ n.logfile = logfile
+ n.logfile_name = logfile_name
- # remember the process is running
- self.all_procs[node.name] = n
+ # remember the process is running
+ self.all_procs[node.name] = n
- return 'R'
+ return 'R'
except Exception as e :
log_traceback()
@@ -262,7 +262,7 @@ class runner(object):
# note the termination of the process at the end of the log file
logfile = self.all_procs[node_name].logfile
- logfile.seek(0,2) # end of file
+ logfile.seek(0, os.SEEK_END) # end of file
logfile.write('\n%s exit=%s\n'%(datetime.datetime.now(),status))
logfile.close()