def start_process(cmd, name, live_output=False): proc = Process(cmd, name) logfile = f'{cwd}/logs/{name}.log' print_info(f"Running {proc.cmd}") proc.run(logfile, live_output=live_output) return proc
def main(): process = None try: config = {} Config.load(config) LoggingHelper.init(config) process = Process() process.open(config) process.run() return 0 except KeyboardInterrupt: return 0 except Exception as ex: _logger.exception(ex) return 1 finally: if process is not None: process.close()
def createProcess(self, filename): try: proc = Process(filename, self.next_pid, self.frgrnd) self.frgrnd.append(proc.getMain()) self.next_pid += 1 self.total_threads += 1 except ex.ImproperInstructionError: DebugPrint(f"[Dispatcher] {filename} failed initialization") gui_mailbox.put(c.Cmd_Error(f"{filename} is miswritten, please update and try again")) except ex.MemoryAllocationError: self.wait_mem.append(filename) # including this just to cover my bases except: DebugPrint(f"[Dispatcher] {filename} failed initialization... weirdly") gui_mailbox.put(c.Cmd_Error(f"{filename} failed init... weirdly ()"))
def main(file_name): if os.path.isdir(file_name): # TODO: If the file name is directory then it will search all the file with *.ي and process all file pass elif os.path.isfile(file_name): py_content = '' # Appending print function code to the file with open(os.path.join(script_dir, 'include.py'), 'r') as file: py_content += file.read() # Reading file to process the text with open(file_name, 'r') as file: # Process all content of the file py_content += Process(file, num_dict, keyword_dict, function_dict).process() # Splitting file name to remove existing extension in order to add python extension file_split = file_name.split(".") # Name of the python file to be created py_file = file_split[0] + ".py" # Creating the python file f = open(py_file, "w") # And then writing content to the python file f.write(py_content) else: sys.exit("'" + file_name + "'" + " " + FileError.INVALID_FILE.value)
def create_event(self, activate_at: Arrow, p_id: int) -> Event: """Create a new process""" process = Process(process_id=p_id, run_time=rand_exp_float(self.config['burst_lambda']), created_at=activate_at) return Event(created_at=activate_at, event_type=EVENT_TYPES['NEW'], process=process)
def add_process_to_queue(self): """ Function to create a Process Object from the inserted data in the Window """ # Get Data From Window arrival_time = self.spin_arrival_time.value() burst_time = self.spin_burst_time.value() niceness = self.spin_niceness.value() deadline = self.spin_deadline.value() # Check if the given deadline is even possible if arrival_time + burst_time > deadline: self.display_text( "Couldnt add Process because its not doable within its deadline!" ) return # Create Process based on Data PROCESS_LIST.append( Process(arrival_time, burst_time, niceness, deadline)) # Prep output for text box pid = PROCESS_LIST[-1].get_pid() arrival_time = PROCESS_LIST[-1].get_arrival_time() burst_time = PROCESS_LIST[-1].get_burst_time() niceness = PROCESS_LIST[-1].get_niceness() deadline = PROCESS_LIST[-1].get_deadline() # Give user feedback to successful creatin an Process self.terminal_output.append( f"{HELPER[0].get_current_time()}Process added.\tPID: {pid}\tArrival: {arrival_time}\tBurst: {burst_time}\tPriority: {niceness}\tDeadline: {deadline}" ) self.terminal_output.ensureCursorVisible() # Reset the spinboxes values self.reset_spin_boxes() return
# Make sure the game is properly defined validate(src.utils.game_module) # For debugging with heapy. if args.debug: src.debug.init_debug(comm.Get_rank()) send = src.debug.debug_send(comm.send) recv = src.debug.debug_recv(comm.recv) abort = src.debug.debug_abort(comm.Abort) initial_position = src.utils.game_module.initial_position() process = Process(comm.Get_rank(), comm.Get_size(), comm, send, recv, abort, stats_dir=args.statsdir) if process.rank == process.root: initial_gamestate = GameState(GameState.INITIAL_POS) initial_job = Job(Job.LOOK_UP, initial_gamestate, process.rank, Job.INITIAL_JOB_ID) process.add_job(initial_job) process.run() comm.Barrier()
switch_counter = 1 # Variables for output calculations total_runtime = 0 total_waiting = 0 total_context = 0 # Flags for processes running_process = None waiting_process = None cpu_busy = False context_switch = False # Creates processes from the text files in the processes folder for i in range(1, number_of_processes + 1): process[i] = Process() process[i].create('processes/process%d.txt' % i) while True: # adds processes to the ready queue at their specified arrival times for i in range(1, number_of_processes + 1): if sysclock == process[i].arrival_time: ready_queue.put(process[i]) print('Process ' + repr(process[i].pid) + ' has arrived.') print('Time %d' % sysclock + ': ') # Display the running and waiting processes. if running_process != None: print('Currently running process ' + repr(running_process.pid) + '.') else:
def validate(mod): try: getattr(mod, 'initial_position') getattr(mod, 'do_move') getattr(mod, 'gen_moves') getattr(mod, 'primitive') except AttributeError as e: print "Could not find method", e.args[0] raise # Make sure the game is properly defined validate(src.utils.game_module) # Set up our logging system lvl = logging.CRITICAL if args.debug: lvl = logging.DEBUG logging.basicConfig(filename='logs/solver_log' + str(comm.Get_rank()) + '.log', filemode='w', level=lvl) initial_position = src.utils.game_module.initial_position() process = Process(comm.Get_rank(), comm.Get_size(), comm, NP=args.numpy) if process.rank == process.root: initial_gamestate = GameState(GameState.INITIAL_POS) initial_job = Job(Job.LOOK_UP, initial_gamestate, process.rank, Job.INITIAL_JOB_ID) process.add_job(initial_job) process.run()
from src.process import Process process = Process() for i in range(0, 100): print(f'Starting year number {i + 1} without process') print(f'Current population is {len(process.inland.inland_population.individuals)}') print(f'Current iq distribution is {process.inland.current_iq_distribution}') # print(f'Current average age is {process.inland.current_iq_distribution}') process.skip_process() process.inland.inland_population.get_current_iq_distribution(draw=True) for i in range(0, 10000): print(f'Year of the process {i + 1}') print(f'Current population is {len(process.inland.inland_population.individuals)}') print(f'Current iq distribution is {process.inland.current_iq_distribution}') process.execute_process() process.inland.inland_population.get_current_iq_distribution(draw=True)
getattr(mod, 'initial_position') getattr(mod, 'do_move') getattr(mod, 'gen_moves') getattr(mod, 'primitive') except AttributeError as e: print("Could not find method"), e.args[0] raise # Make sure the game is properly defined validate(src.utils.game_module) # Set up our logging system lvl = logging.CRITICAL if args.debug: lvl = logging.DEBUG logging.basicConfig(filename='logs/solver_log' + str(comm.Get_rank()) + '.log', filemode='w', level=lvl) initial_position = src.utils.game_module.initial_position() process = Process(comm.Get_rank(), comm.Get_size(), comm, NP=args.numpy) if process.rank == process.root: initial_gamestate = GameState(GameState.INITIAL_POS) initial_job = Job(Job.LOOK_UP, initial_gamestate, process.rank, Job.INITIAL_JOB_ID) process.add_job(initial_job) process.run()
# Make sure the game is properly defined validate(src.utils.game_module) # For debugging with heapy. if args.debug: src.debug.init_debug(comm.Get_rank()) isend = src.debug.debug_send(comm.isend) recv = src.debug.debug_recv(comm.recv) abort = src.debug.debug_abort(comm.Abort) initial_position = src.utils.game_module.initial_position() process = Process( comm.Get_rank(), comm.Get_size(), comm, isend, recv, abort, stats_dir=args.statsdir ) if process.rank == process.root: initial_gamestate = GameState(GameState.INITIAL_POS) initial_job = Job( Job.LOOK_UP, initial_gamestate, process.rank, Job.INITIAL_JOB_ID ) process.work.put(initial_job)
default=os.getcwd()) print '' return vars(parser.parse_args()) if __name__ == '__main__': try: s = time.time() logging.basicConfig(filename='{0}/sfinder.log'.format( os.path.expanduser('~')), format='%(asctime)s [%(levelname)s] %(message)s', level=logging.DEBUG, datefmt='%m/%d/%Y %H:%M:%S') Process(P_args()) e = time.time() print '\n[INFO] Program Finished in: {0}\n'.format( timedelta(seconds=round(e - s))) logging.info('Processing Finished Sucessfully!!\n') sys.exit(0) except KeyboardInterrupt: print '\n\n[ERROR] Program terminated by User!\n' logging.error('Stamp-Finder was killed by User!\n') except Exception as e: print '\n[ERROR] {0}'.format(e) print 'Check ~/sfinder.log for more information. :(\n' logging.critical(e) logging.critical(traceback.format_exc())