def test_daemonize(self): """Detach(daemonize=True)""" fd = tempfile.NamedTemporaryFile(delete=False) try: with detach.Detach(None, sys.stderr) as d1: if not d1.pid: with detach.Detach(None, sys.stderr, None, daemonize=True) as d2: if not d2.pid: fd.close() fd.write('parent is still running') fd.close() except SystemExit as e: self.assertEqual(e.code, 0) time.sleep(0.5) fd.seek(0) self.assertEqual('', fd.read()) fd.close() os.unlink(fd.name)
def test_exclude_fds(self): """Detach(close_fds=True, exclude_fds=[fd])""" try: fd = tempfile.NamedTemporaryFile(delete=False) with detach.Detach(None, sys.stderr, None, close_fds=True, exclude_fds=[fd]) as d: if d.pid: fd.close() else: fd.close() except SystemExit as e: self.assertEqual(e.code, 0) os.unlink(fd.name)
def __init__(self): rospy.init_node('navigation_controller_node') initial = InitialPosePublisher() self.detach_controller = detach.Detach() self.client = actionlib.SimpleActionClient('move_base', MoveBaseAction) self.next_goal_publisher = rospy.Publisher('navigation/next_goal', Int32) self.park_publisher = rospy.Publisher('navigation/park_request', Int32) self.path_subscriber = rospy.Subscriber('navigation/path', Int32MultiArray, self.set_path) self.client.wait_for_server() self.path = None self.cart_number = 1 # get from upper layer self.current_pose_index = 0 self.goal_threshold_x = 0.1 self.goal_threshold_y = 0.1 self.next_goal_pose = None self.next_goal = None rospy.sleep(3)
def test_detach(self): """Detach()""" fd = tempfile.NamedTemporaryFile(delete=False) try: want_pid = None with detach.Detach(None, sys.stderr, None) as d: if d.pid: want_pid = d.pid else: pid = os.getpid() fd.write(str(pid)) fd.close() except SystemExit as e: self.assertEqual(e.code, 0) time.sleep(0.5) fd.seek(0) have_pid = int(fd.read()) fd.close() self.assertEqual(want_pid, have_pid) os.unlink(fd.name)
def test_close_fds(self): """Detach(close_fds=True)""" fd = tempfile.NamedTemporaryFile(delete=False) testfd = tempfile.NamedTemporaryFile(delete=False) try: with detach.Detach(None, sys.stderr, None, close_fds=True, exclude_fds=[fd]) as d: if d.pid: testfd.close() else: try: testfd.close() except IOError as e: fd.write(str(e.errno)) fd.close() except SystemExit as e: self.assertEqual(e.code, 0) time.sleep(0.5) fd.seek(0) self.assertEqual(9, int(fd.read())) os.unlink(fd.name) os.unlink(testfd.name)
parser.add_argument( "--cul-path", default="/dev/ttyACM0", help="Path to usbmodem path of CUL, defaults to /dev/ttyACM0") args = parser.parse_args() db.create_all() if args.detach: # init logger from logbook import FileHandler log_handler = FileHandler('server.log') log_handler.push_application() import detach with detach.Detach(daemonize=True) as d: if d.pid: print( "started process {} in background with log to server.log". format(d.pid)) else: main(args) else: # init logger from logbook.more import ColorizedStderrHandler log_handler = ColorizedStderrHandler() log_handler.push_application() main(args)