class CppSim(ProcessWorkerThread): def handle_eval(self, record): val = np.nan # Continuously check for new outputs from the subprocess self.process = Popen(['./sumfun_ext', array2str(record.params[0])], stdout=PIPE, bufsize=1, universal_newlines=True) for line in self.process.stdout: try: val = float(line.strip()) # Try to parse output if val > 350: # Terminate if too large self.process.terminate() self.finish_success(record, 350) return except ValueError: # If the output is nonsense we terminate logging.warning("Incorrect output") self.process.terminate() self.finish_cancelled(record) return self.process.wait() rc = self.process.poll() # Check the return code if rc < 0 or np.isnan(val): logging.info("WARNING: Incorrect output or crashed evaluation") self.finish_cancelled(record) else: self.finish_success(record, val)
class CppSim(ProcessWorkerThread): def handle_eval(self, record): self.process = Popen( ['./sumfun_ext', array2str(record.params[0])], stdout=PIPE) val = np.nan # Continuously check for new outputs from the subprocess while True: output = self.process.stdout.readline() if output == '' and self.process.poll( ) is not None: # No new output break if output: # New intermediate output try: val = float(output.strip()) # Try to parse output if val > 350: # Terminate if too large self.process.terminate() self.finish_success(record, 350) return except ValueError: # If the output is nonsense we terminate logging.warning("Incorrect output") self.process.terminate() self.finish_cancelled(record) return rc = self.process.poll() # Check the return code if rc < 0 or np.isnan(val): logging.info("WARNING: Incorrect output or crashed evaluation") self.finish_cancelled(record) else: self.finish_success(record, val)
def run_cmd_noout(cmd_data): cmd = cmd_data[0] output = cmd_data[1] c = cmd[:-1] timeout = cmd[-1] display("Executing command: %s" % " ".join(c)) current_time = time.time() f = open(output, 'w') if timeout: process = Popen(c, stdout=f, stderr=STDOUT) while time.time() < current_time + timeout and process.poll() is None: time.sleep(5) if process.poll() is None: display_error( "Timeout of %s reached. Aborting thread for command: %s" % (timeout, " ".join(c)) ) process.terminate() else: Popen(c, stdout=f, stderr=STDOUT).wait() f.close() return cmd_data
def run_cmd(cmd): # c = [] # for cm in cmd[:-1]: # if ' ' in cm: # c.append('"' + cm + '"') # else: # c.append(cm) c = cmd[:-1] timeout = cmd[-1] display("Executing command: %s" % " ".join(c)) current_time = time.time() if timeout: process = Popen(c) while time.time() < current_time + timeout and process.poll() is None: time.sleep(5) if process.poll() is None: display_error( "Timeout of %s reached. Aborting thread for command: %s" % (timeout, " ".join(c)) ) process.terminate() else: Popen(c).wait() return cmd
class DummySim(ProcessWorkerThread): def handle_eval(self, record): self.process = Popen(['./sumfun_ext', array2str(record.params[0])], stdout=PIPE) val = np.nan # Continuously check for new outputs from the subprocess while True: output = self.process.stdout.readline() if output == '' and self.process.poll() is not None: # No new output break if output: # New intermediate output try: val = float(output.strip()) # Try to parse output if val > 350: # Terminate if too large self.process.terminate() self.finish_success(record, 350) return except ValueError: # If the output is nonsense we terminate logging.warning("Incorrect output") self.process.terminate() self.finish_failure(record) return rc = self.process.poll() # Check the return code if rc < 0 or np.isnan(val): logging.warning("Incorrect output or crashed evaluation") self.finish_failure(record) else: self.finish_success(record, val)
def terminate(self): """Terminates the process""" # Don't terminate a process that we know has already died. if self.returncode is not None: return if self._job: winprocess.TerminateJobObject(self._job, 127) self.returncode = 127 else: Popen.terminate(self)
def terminate(self): """Terminates the process""" # Don't terminate a process that we know has already died. if self.returncode is not None: return if self._job: winprocess.TerminateJobObject(self._job, 127) self.returncode = 127 else: Popen.terminate(self)
stream = raw_input("Should I stream video or take pictures (v/p)? ") preview = raw_input("Should I display video preview on Pi (y/n)? ") print "Running..." #http://www.raspberry-projects.com/pi/pi-hardware/raspberry-pi-camera/streaming-video-using-vlc-player #http://www.diveintopython.net/scripts_and_streams/stdin_stdout_stderr.html #Ouput video (record) => stream => stdout => | => cvlc livestream => browser if (stream == "v" or stream == "V"): try: live = Popen(["./livestream.sh"]) finally: print "\n\nExiting..." live.terminate() elif (stream == "p" or stream == "P"): length = float(raw_input("How long should I run (in minutes): "))*60 interval = float(raw_input("How often should I take a picture (in seconds): ")) camera = PiCamera() camera.annotate_background = picamera.Color('black') camera.rotation = 180 camera.resolution = (640, 480) counter = 0 try: if (preview == "y" or preview == "Y"): camera.start_preview() while (counter <= length):