Exemple #1
0
 def shutdown(self):
     record = filemgt.format(
         logging.LogRecord(
             self.__class__.__name__, logging.DEBUG, None, None,
             "RECEIVED ABORT SIGNAL: " + self.name + ", command = " +
             self.args[0], None, None))
     self.log_queue.put(record)
     self.exit.set()
Exemple #2
0
 def terminate(self):
     record = filemgt.format(
         logging.LogRecord(
             self.__class__.__name__, logging.INFO, None, None,
             "TERMINATING: " + self.name + ", command = " + self.args[0],
             None, None))
     self.log_queue.put(record)
     self.shutdown()
     time.sleep(0.2)
     multiprocessing.Process.terminate(self)
Exemple #3
0
 def enforce_limits(self, pid):
     limit = 1536  # each reasoning process is not allowed to use up more than 1.5GB of memory
     memory = get_memory(pid)
     #enforce memory limit
     if memory > limit:
         record = filemgt.format(
             logging.LogRecord(
                 self.__class__.__name__, logging.INFO, None, None,
                 "MEMORY EXCEEDED: " + self.name + ", command = " +
                 self.args[0], None, None))
         self.log_queue.put(record)
         self.shutdown()
     # enforce time limit
     if self.cputime > self.timeout:
         record = filemgt.format(
             logging.LogRecord(
                 self.__class__.__name__, logging.INFO, None, None,
                 "TIME EXCEEDED: " + self.name + ", command = " +
                 self.args[0], None, None))
         self.log_queue.put(record)
         self.shutdown()
Exemple #4
0
 def run(self):
     record = filemgt.format(
         logging.LogRecord(
             self.__class__.__name__, logging.INFO, None, None,
             "STARTING: " + self.name + ", command = " + self.args[0], None,
             None))
     self.log_queue.put(record)
     out_file = open(self.output_filename, 'w')
     sp = startSubprocessWithOutput(self.args, out_file,
                                    self.input_filenames)
     self.previous_cputime = 0
     self.current_cputime = 0
     while sp.poll() is None and not self.exit.is_set():
         time.sleep(1)
         self.update_cputime(sp.pid)
         self.enforce_limits(sp.pid)
     if self.exit.is_set():
         # interrupted
         record = filemgt.format(
             logging.LogRecord(
                 self.__class__.__name__, logging.DEBUG, None, None,
                 "ABORTING: " + self.name + ", command = " + self.args[0],
                 None, None))
         self.log_queue.put(record)
         #			print "RECEIVED ABORT SIGNAL"
         (_, stdoutdata) = terminateSubprocess(sp)
         if stdoutdata:
             stdoutdata = re.sub(r'[^\w]', ' ', stdoutdata)
             stdoutdata = ' '.join(stdoutdata.split())
             record = filemgt.format(
                 logging.LogRecord(
                     self.__class__.__name__, logging.INFO, None, None,
                     "STDOUT from " + self.name + ": " + str(stdoutdata),
                     None, None))
             self.log_queue.put(record)
         self.result_queue.put((self.args[0], -1, stdoutdata))
         record = filemgt.format(
             logging.LogRecord(
                 self.__class__.__name__, logging.INFO, None, None,
                 "ABORTED: " + self.name + ", command = " + self.args[0],
                 None, None))
         self.log_queue.put(record)
         self.update_cputime(sp.pid)
         out_file.flush()
         out_file.close()
         self.writeHeader()
         self.done.set()
         return True
     # finished normally, i.e., sp.poll() determined the subprocess has terminated by itself
     self.update_cputime(sp.pid)
     self.result_queue.put((self.args[0], sp.returncode, None))
     record = filemgt.format(
         logging.LogRecord(
             self.__class__.__name__, logging.INFO, None, None,
             "FINISHED: " + self.name + ", command = " + self.args[0], None,
             None))
     self.log_queue.put(record)
     out_file.flush()
     out_file.close()
     self.writeHeader()
     self.done.set()
     return True