From 4c85d08556c8a1e278da8bc8420d30e7d88382ab Mon Sep 17 00:00:00 2001 From: Hal Simpson <hasimpson@usgs.gov> Date: Thu, 4 Feb 2016 16:06:16 -0700 Subject: [PATCH] Doing the while loop the python way, and printing errors/information to stderr, to not interfere with other output programs --- geomagio/imfv283/GOESIMFV283Factory.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/geomagio/imfv283/GOESIMFV283Factory.py b/geomagio/imfv283/GOESIMFV283Factory.py index e251f27e9..aa96b6dee 100644 --- a/geomagio/imfv283/GOESIMFV283Factory.py +++ b/geomagio/imfv283/GOESIMFV283Factory.py @@ -2,6 +2,7 @@ from IMFV283Factory import IMFV283Factory import subprocess +import sys from obspy.core import Stream @@ -46,7 +47,6 @@ class GOESIMFV283Factory(IMFV283Factory): self.directory = directory self.getdcpmessages = getdcpmessages self.server = server - self.maxserver = len(self.server) self.user = user self.log_file_name = self.observatory + '.log' self.criteria_file_name = self.observatory + '.sc' @@ -110,23 +110,22 @@ class GOESIMFV283Factory(IMFV283Factory): Messages from getDcpMessages """ self._fill_criteria_file(starttime, endtime) - currentserver = 0 - while (currentserver < self.maxserver): - print self.server[currentserver] + for server in self.server: + print >> sys.stderr, server proc = subprocess.Popen( [self.getdcpmessages, - '-h ' + self.server[currentserver], + '-h ' + server, '-u ' + self.user, '-f ' + self.directory + '/' + self.criteria_file_name, '-t 60', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (output, error) = proc.communicate() - print error + print >> sys.stderr, error if error.find(self.javaerror) >= 0: - print 'Error: could not connect to %s' % \ - self.server[currentserver] - currentserver += 1 + print >> sys.stderr, \ + 'Error: could not connect to %s' % \ + server continue break -- GitLab