jeudi 2 septembre 2021

how to execute function in random manner with try and except?

I have a piece of concurrent scenario code which is below. I want to call these functions which are in try blocks in random order instead of sequential. so, how it can be done?

def foreground_tasks(self): logging.debug('mutitasking_MultiTaskingOnChromeBook: fore_ground_jobs(): Entered') time1 = datetime.now() time2 = datetime.now() time_duration_raw = time2 - time1 time_duration_secs = time_duration_raw.total_seconds()

    iteration=1
    while time_duration_secs <= self.test_duration_secs:
        try:                
            try:
                self.play_local_audio()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: play_local_audio(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-play_local_audio-%s'%iteration)
            try:
                self.app_install_uninstall()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: app_install_uninstall(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-app_install_uninstall-%s'%iteration)
            try:
                self.graphic_stress()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: graphic_stress(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-graphic_stress-%s'%iteration)
            try:
                self.youtube_stream()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: youtube_stream(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-youtube_stream-%s'%iteration)
            try:
                self.camera_take_picture()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: camera_take_picture(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-camera_take_picture-%s'%iteration)
            try:
                self.camera_record_video()
            except Exception as e:
                self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: camera_record_video(): Error in FG JOBs.. %s"%iteration)
                graphics_utils.take_screenshot(self.resultsdir, 'screenshot-camera_record_video-%s'%iteration)
        except Exception as e:
            logging.info("mutitasking_MultiTaskingOnChromeBook: fore_ground_jobs(): Error in Foreground JOBS..%s"%str(e))
            graphics_utils.take_screenshot(self.resultsdir, 'screenshot-%s'%iteration)
            self.thread_errors.append("mutitasking_MultiTaskingOnChromeBook: fore_ground_jobs(): Error in Foreground JOBs.. %s"%iteration)

        time2 = datetime.now()
        time_duration_raw = time2 - time1
        time_duration_secs = time_duration_raw.total_seconds()

        iteration=iteration+1
        logging.debug("mutitasking_MultiTaskingOnChromeBook: fore_ground_jobs(): iteration: %s"%iteration)
    logging.debug('mutitasking_MultiTaskingOnChromeBook: fore_ground_jobs(): Exiting: Final iteration: %s'%iteration)



Aucun commentaire:

Enregistrer un commentaire