def hold_message(self, destination, data, headers):
        """ Calls the reduction script. """
        logger.debug("holding thread")
        message = Message()
        message.populate(data)

        self.update_child_process_list()
        if not self.should_proceed(message):  # wait while the run shouldn't proceed
            # pylint: disable=maybe-no-member
            reactor.callLater(10, self.hold_message,  # pragma: no cover
                              destination, data,
                              headers)

            return

        if self.should_cancel(message):
            self.cancel_run(message)  # pylint: disable=maybe-no-member
            return


        if not os.path.isfile(MISC['post_process_directory']):
            logger.warning("Could not find autoreduction post processing file "
                           "- please contact a system administrator")
        python_path = sys.executable
        logger.info("Calling: %s %s %s %s",
                    python_path, MISC['post_process_directory'], destination,
                    message.serialize(limit_reduction_script=True))
        proc = subprocess.Popen([python_path,
                                 MISC['post_process_directory'],
                                 destination,
                                 message.serialize()])  # PPA expects json data
        self.add_process(proc, message)
예제 #2
0
 def _remove_with_wait(self, remove_folder, full_path):
     """ Removes a folder or file and waits for it to be removed. """
     file_deleted = False
     for sleep in [0, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20]:
         try:
             if remove_folder:
                 os.removedirs(full_path)
             else:
                 if os.path.isfile(full_path):
                     os.remove(full_path)
                     file_deleted = True
                 elif sleep == 20:
                     logger.warning(
                         "Unable to delete file %s, file could not be found",
                         full_path)
                 elif file_deleted is True:
                     logger.debug("file %s has been successfully deleted",
                                  full_path)
                     break
         except OSError as exp:
             if exp.errno == errno.ENOENT:
                 # File has been deleted
                 break
         time.sleep(sleep)
     else:
         self.log_and_message("Failed to delete %s" % full_path)
예제 #3
0
 def _remove_directory(self, directory):
     """
     Helper function to remove a directory. shutil.rmtree cannot be used as it is not robust
     enough when folders are open over the network.
     """
     try:
         for target_file in os.listdir(directory):
             full_path = os.path.join(directory, target_file)
             if os.path.isdir(full_path):
                 self._remove_directory(full_path)
             else:
                 if os.path.isfile(full_path):
                     self._remove_with_wait(False, full_path)
                 else:
                     logger.warning("Unable to find file %s.", full_path)
         self._remove_with_wait(True, directory)
     except Exception as exp:
         self.log_and_message(
             "Unable to remove existing directory %s - %s" %
             (directory, exp))