def parse(): while True: if abort: return try: msg = pull.recv_json() logger.d('pull received message = {}'.format(msg)) func = msg.get('func') if func == 'play': q.put({'cmd': s.play, 'args': msg.get('data')}) elif func == 'stop': q.put({'cmd': s.stop, 'args': msg.get('data')}) elif func == 'volume': q.put({'cmd': s.volume, 'args': msg.get('data')}) elif func == 'pause': q.put({'cmd': s.pause, 'args': msg.get('data')}) elif func == 'resume': q.put({'cmd': s.resume, 'args': msg.get('data')}) else: logger.w('not found function.') except KeyboardInterrupt: raise except Exception: logger.e('Unexpected error: {}'.format(str(sys.exc_info()[0]))) logger.e(traceback.format_exc())
def on_do_function(self): if not q.empty(): try: req = q.get() cmd = req.get('cmd') args = req.get('args') cmd(args) except Exception: logger.e('Unexpected do function on message loop.') logger.e(traceback.format_exc()) time.sleep(0.1)
def run(self): self.run_async() try: while True: if self.aborted: break time.sleep(0.5) except KeyboardInterrupt: logger.d('keyboard Ctrl+C in simple_run_loop.run()') self.on_keyboard_interrupt() raise except Exception: logger.e('Unexpected error: {}'.format(str(sys.exc_info()[0]))) logger.e(traceback.format_exc()) raise finally: self.aborted = True logger.i('finish run')
def __message_loop(self): try: logger.d('start runloop') self.on_start_runloop() while True: try: if self.aborted: return self.on_do_function() except Exception as exception: ret = self.on_exception_at_runloop(exception) if (ret == SimpleRunLoop.CONTINUE): logger.d('continue runloop') continue else: logger.e('Unexpected error: {}'.format( str(sys.exc_info()[0]))) logger.e(traceback.format_exc()) logger.e('exit runloop by exception') return finally: self.run_loop_finished = True self.on_finish_runloop() logger.d('finished runloop')
finally: if s is not None: s.close() return None port = None s = None try: flask.check_error() logger.i("searching controller....") port = find_controller_port() if port is None: logger.e('game pad not found.') exit logger.i("find port: " + str(port)) s = serial.Serial(port, 9600) logger.i("gamepad server has started on port" + str(tcp_port)) while True: line = s.readline().strip() gamepad_state = line socket.send_string(line) except: logger.e('HwControllerManager.init() failed.' + str(sys.exc_info()[0])) logger.e(traceback.format_exc()) finally:
[[0] * 4]) # 深度のサイズ変換 d = cv2.applyColorMap(d.astype(np.uint8), cv2.COLORMAP_BONE) scaledd = get_scled_rgb_image(d, scale, scale) framed = resize2(scaledd, (FRAME_WIDTH, FRAME_HEIGHT), (-4, 0), [[0] * 4]) # 深度を最後に添付する frame = np.hstack( (framec.reshape(FRAME_WIDTH * FRAME_HEIGHT, 3), framed[:, :, 0].reshape(FRAME_WIDTH * FRAME_HEIGHT, 1))) frame = frame.reshape(FRAME_WIDTH, FRAME_HEIGHT, 4) send_array(socket, frame) except: logger.e("initialize realsense failed.:" + str(sys.exc_info()[0])) logger.e(traceback.format_exc()) finally: if dev is not None: dev.stop() # pyrs.stop() if socket is not None: socket.close() if context is not None: context.term()