def trigger(self):
if self.type == TRAFFIC_FLOW_ONE_SHOT:
sleep(int(self.offset))
print "Started command at ", str(datetime.now())
sys.stdout.flush()
#os.system(self.cmd + " &")
try:
cmd_list = self.cmd.split(' ')
print cmd_list
print self.cmd
sys.stdout.flush()
p = subprocess.Popen(cmd_list,shell=False)
except:
print "Error running command: ", sys.exec_info()[0]
elif self.type == TRAFFIC_FLOW_EXPONENTIAL:
pass
elif self.type == TRAFFIC_FLOW_PERIODIC:
pass
python类exec_info()的实例源码
def read_images (path, sz=None):
c = 0
X,y = [], []
for dirname, dirnames, filenames in os.walk(path):
for subdirname in dirnames:
subject_path = os.path.join(dirname, subdirname)
for filename in os.listdir(subject_path):
try:
if (filename == ".drectory"):
continue
filepath = os.path.join(subject_path, filename)
im = cv2.imread(os.path.join(subject_path, filename), cv2.IMREAD_GRAYSCALE)
if (sz is not None):
im = cv2.resize(im, sz)
X.append(np.asarray(im, dtype=np.uint8))
y.append(c)
except IOError, (errno, strerror):
print "I/O error({0}): {1}".format(errno,strerror)
except:
print "Unexpected error:", sys.exec_info()[0]
raise
c= c+1
return [X,y]
def run_program(self,string):
print(string)
try:
process = subprocess.Popen(string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, err = process.communicate()
print(err)
if process.returncode != 0:
print("Non-zero exit status:")
print(process.returncode)
raise SystemExit
except:
print("Unexpected error:")
print(sys.exec_info())
raise SystemExit
def _handleTime(self, offset, line):
# Accept it, but do not do anything with it yet.
try:
event_time = iso8601.parse_date(line[offset:-1])
except TypeError:
raise TypeError(_u("Failed to parse %r, got %r")
% (line, sys.exec_info[1]))
self.client.time(event_time)