def cancel_simulation_job(backoff_time_sec=1.0, max_retry_attempts=5): """ros service call to cancel simulation job Args: backoff_time_sec(float): backoff time in seconds max_retry_attempts (int): maximum number of retry """ import rospy from markov.rospy_wrappers import ServiceProxyWrapper from robomaker_simulation_msgs.srv import Cancel requestCancel = ServiceProxyWrapper("/robomaker/job/cancel", Cancel) try_count = 0 while True: try_count += 1 response = requestCancel() logger.info( "cancel_simulation_job from ros service call response: {}".format(response.success) ) if response and response.success: time.sleep(ROBOMAKER_CANCEL_JOB_WAIT_TIME) return if try_count > max_retry_attempts: simapp_exit_gracefully() backoff_time = (pow(try_count, 2) + random.random()) * backoff_time_sec time.sleep(backoff_time)
def restart_simulation_job(simulation_job_arn, aws_region): logger.info("restart_simulation_job: make sure to shutdown simapp first") if simulation_job_arn: session = boto3.session.Session() robomaker_client = session.client('robomaker', region_name=aws_region) robomaker_client.restart_simulation_job(job=simulation_job_arn) else: simapp_exit_gracefully()
def cancel_simulation_job(simulation_job_arn, aws_region): logger.info("cancel_simulation_job: make sure to shutdown simapp first") if simulation_job_arn: session = boto3.session.Session() robomaker_client = session.client('robomaker', region_name=aws_region) robomaker_client.cancel_simulation_job(job=simulation_job_arn) time.sleep(ROBOMAKER_CANCEL_JOB_WAIT_TIME) else: simapp_exit_gracefully()
def exit_if_trainer_done(checkpoint_dir, s3_writer): '''Helper method that shutsdown the sim app if the trainer is done checkpoint_dir - direcotry where the done file would be downloaded to ''' if should_stop(checkpoint_dir): unsubscribe_from_save_mp4 = ServiceProxyWrapper( '/racecar/save_mp4/unsubscribe_from_save_mp4', Empty) unsubscribe_from_save_mp4(EmptyRequest()) s3_writer.upload_to_s3() logger.info("Received termination signal from trainer. Goodbye.") simapp_exit_gracefully()
def cancel_simulation_job(backoff_time_sec=1.0, max_retry_attempts=5): """ros service call to cancel simulation job Args: backoff_time_sec(float): backoff time in seconds max_retry_attempts (int): maximum number of retry """ import rospy from robomaker_simulation_msgs.srv import Cancel time.sleep(ROBOMAKER_CANCEL_JOB_WAIT_TIME) simapp_exit_gracefully(simapp_exit=SIMAPP_DONE_EXIT)
def exit_if_trainer_done(checkpoint_dir, s3_writer, rollout_idx): '''Helper method that shutsdown the sim app if the trainer is done checkpoint_dir - direcotry where the done file would be downloaded to ''' if should_stop(checkpoint_dir): is_save_mp4_enabled = rospy.get_param('MP4_S3_BUCKET', None) and rollout_idx == 0 if is_save_mp4_enabled: unsubscribe_from_save_mp4 = ServiceProxyWrapper('/racecar/save_mp4/unsubscribe_from_save_mp4', Empty) unsubscribe_from_save_mp4(EmptyRequest()) s3_writer.upload_to_s3() logger.info("Received termination signal from trainer. Goodbye.") simapp_exit_gracefully()
def exit_if_trainer_done(checkpoint_dir, simtrace_video_s3_writers, rollout_idx): """Helper method that shutsdown the sim app if the trainer is done checkpoint_dir - direcotry where the done file would be downloaded to """ if should_stop(checkpoint_dir): is_save_mp4_enabled = rospy.get_param("MP4_S3_BUCKET", None) and rollout_idx == 0 if is_save_mp4_enabled: unsubscribe_from_save_mp4 = ServiceProxyWrapper( "/racecar/save_mp4/unsubscribe_from_save_mp4", Empty ) unsubscribe_from_save_mp4(EmptyRequest()) # upload simtrace and mp4 into s3 bucket for s3_writer in simtrace_video_s3_writers: s3_writer.persist(utils.get_s3_kms_extra_args()) logger.info("Received termination signal from trainer. Goodbye.") simapp_exit_gracefully()
def exit_gracefully(self, signum, frame): self.terminate_now = True logger.info("DoorMan: received signal {}".format(signum)) simapp_exit_gracefully(simapp_exit=SIMAPP_DONE_EXIT)