def run_cmd(cmd, run_name=None): import imp module = imp.new_module(run_name) setattr(module, '__name__', run_name) setattr(module, '__package__', None) # Hide the current module if it exists. old_module = sys.modules.get(run_name) sys.modules[run_name] = module try: code = compile(cmd, '<string>', 'exec') exec(code, module.__dict__, module.__dict__) except SyntaxError as ex: traceback.print_exception(SyntaxError,ex,sys.exc_info()[2],0) c.legion_runtime_set_return_code(1) # Wait for execution to finish here before removing the module # because executing tasks might still need to refer to it future = c.legion_runtime_issue_execution_fence( top_level.runtime[0], top_level.context[0]) # block waiting on the future c.legion_future_wait(future, True, ffi.NULL) c.legion_future_destroy(future) # Make sure our module gets deleted to clean up any references # to variables the user might have made remove_all_aliases(module) if old_module is not None: sys.modules[run_name] = old_module del module
def run_cmd(cmd, run_name=None): import imp module = imp.new_module(run_name) setattr(module, '__name__', run_name) setattr(module, '__package__', None) # Hide the current module if it exists. old_module = sys.modules.get(run_name) sys.modules[run_name] = module code = compile(cmd, '<string>', 'eval') exec(code, module.__dict__, module.__dict__) # Wait for execution to finish here before removing the module # because executing tasks might still need to refer to it future = c.legion_runtime_issue_execution_fence(top_level.runtime[0], top_level.context[0]) # block waiting on the future c.legion_future_wait(future, True, ffi.NULL) c.legion_future_destroy(future) # Make sure our module gets deleted to clean up any references # to variables the user might have made if old_module is None: del sys.modules[run_name] else: sys.modules[run_name] = old_module del module
def run_path(filename, run_name=None): import imp module = imp.new_module(run_name) setattr(module, '__name__', run_name) setattr(module, '__file__', filename) setattr(module, '__loader__', None) setattr(module, '__package__', run_name.rpartition('.')[0]) # Hide the current module if it exists. old_module = sys.modules.get(run_name) sys.modules[run_name] = module sys.path.append(os.path.dirname(filename)) with open(filename) as f: code = compile(f.read(), filename, 'exec') exec(code, module.__dict__, module.__dict__) # Wait for execution to finish here before removing the module # because executing tasks might still need to refer to it future = c.legion_runtime_issue_execution_fence(top_level.runtime[0], top_level.context[0]) # block waiting on the future c.legion_future_wait(future, True, ffi.NULL) c.legion_future_destroy(future) # Make sure our module gets deleted to clean up any references # to variables the user might have made if old_module is None: del sys.modules[run_name] else: sys.modules[run_name] = old_module del module
def run_repl(): try: shell = LegionConsole() shell.interact(banner='Welcome to Legion Python interactive console') except (SystemExit, KeyboardInterrupt): pass finally: # Save the history shell.save_history() # Wait for execution to finish here before removing the module # because executing tasks might still need to refer to it future = c.legion_runtime_issue_execution_fence( top_level.runtime[0], top_level.context[0]) # block waiting on the future c.legion_future_wait(future, True, ffi.NULL) c.legion_future_destroy(future) del shell
def run_path(filename, run_name=None): import imp module = imp.new_module(run_name) setattr(module, '__name__', run_name) setattr(module, '__file__', filename) setattr(module, '__loader__', None) setattr(module, '__package__', run_name.rpartition('.')[0]) # Hide the current module if it exists. old_module = sys.modules.get(run_name) sys.modules[run_name] = module sys.path.append(os.path.dirname(filename)) try: with open(filename) as f: code = compile(f.read(), filename, 'exec') exec(code, module.__dict__, module.__dict__) except FileNotFoundError as ex: print("legion_python: can't open file " + str(filename) + ": " + str(ex)) c.legion_runtime_set_return_code(1) except SyntaxError as ex: traceback.print_exception(SyntaxError, ex, sys.exc_info()[2], 0) c.legion_runtime_set_return_code(1) except SystemExit as ex: if ex.code is not None: if isinstance(ex.code, int): c.legion_runtime_set_return_code(ex.code) else: traceback.print_exception(SyntaxError, ex, sys.exc_info()[2], 0) c.legion_runtime_set_return_code(1) # Wait for execution to finish here before removing the module # because executing tasks might still need to refer to it future = c.legion_runtime_issue_execution_fence(top_level.runtime[0], top_level.context[0]) # block waiting on the future c.legion_future_wait(future, True, ffi.NULL) c.legion_future_destroy(future) # Make sure our module gets deleted to clean up any references # to variables the user might have made remove_all_aliases(module) if old_module is not None: sys.modules[run_name] = old_module del module