Welcome to remoteexec's documentation!¶
remoteexec package¶
Subpackages¶
remoteexec.communicate package¶
Submodules¶
remoteexec.communicate.communicator module¶
- class remoteexec.communicate.communicator.CommunicationIO¶
ベースクラス:
object- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.communicate.communicator.CommunicationInterface¶
ベースクラス:
object- init_configure_object(configure_object)¶
- is_alive()¶
- start_command()¶
- stop()¶
- class remoteexec.communicate.communicator.Communicator(connection: CommunicationIO, sync_frequency: float, use_compress: bool = True, log_hook: CommunicationLog | None = None)¶
ベースクラス:
object- client(shared_object, configure_object, conflict: ConflictSolvePolicy, snippet_share_only: bool = True, dump_object_depth: int = -1)¶
- host(reciever: CommunicationInterface)¶
- stop()¶
remoteexec.communicate.exceptions module¶
- exception remoteexec.communicate.exceptions.AttributeCannotUpdateError¶
ベースクラス:
UnsirializeErrorTupleの中身を更新,unhashaableなvalueでsetを更新など
- exception remoteexec.communicate.exceptions.CommunicateCannotStartError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.CommunicateError¶
ベースクラス:
CommunicateException通信エラー
- exception remoteexec.communicate.exceptions.CommunicateException¶
ベースクラス:
Exception例外の基底クラス
- exception remoteexec.communicate.exceptions.CommunicateInitialError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.CommunicateRecvError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.CommunicateSendError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.ExceptionInClientError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.ExceptionInServerError¶
ベースクラス:
CommunicateError通信エラー
- exception remoteexec.communicate.exceptions.SirializeError¶
ベースクラス:
CommunicateExceptionシリアライズエラー
- exception remoteexec.communicate.exceptions.SirializedAttributeNameError¶
ベースクラス:
CommunicateExceptionシリアライズに使えない名前(__開始)が含まれている
- exception remoteexec.communicate.exceptions.SirializedFunctionError¶
ベースクラス:
CommunicateExceptionシリアライズ元の関数の呼び出しエラー
- exception remoteexec.communicate.exceptions.UnsirializeError¶
ベースクラス:
CommunicateExceptionシリアライズデータの復元エラー
remoteexec.communicate.serializer module¶
- class remoteexec.communicate.serializer.SirializeFunctionCaller(out_instance)¶
ベースクラス:
object- function_call(instanceid: int, name: str, args: tuple, kwargs: dict)¶
- class remoteexec.communicate.serializer.SiriarizeDictInstance(obj: object, objdict: Dict[object, object])¶
ベースクラス:
object
- class remoteexec.communicate.serializer.SiriarizeInstance(obj: object, objdict: Dict[str, object], names: Tuple[str], funcs: Tuple[str] | None = None)¶
ベースクラス:
object
- class remoteexec.communicate.serializer.UnsirializeFunctionHook¶
ベースクラス:
object- function_call(instanceid: int, name: str, args: tuple, kwargs: dict)¶
- remoteexec.communicate.serializer.dumps(share_object: object, return_caller: bool = False, snippet_share_only: bool = True, dump_object_depth: int = -1, restore_id_map: dict | None = None) Dict[str, object] | Tuple[Dict[str, object], SirializeFunctionCaller]¶
- remoteexec.communicate.serializer.loads(decoded_data: Dict[str, object], function_hook: UnsirializeFunctionHook | None = None, return_id_map: bool = False) object¶
remoteexec.communicate.sync module¶
- class remoteexec.communicate.sync.ApplyInstance(obj: object, parent: object, nameofparent: str)¶
ベースクラス:
object
- class remoteexec.communicate.sync.SyncInstance(instance_id: int, value: object)¶
ベースクラス:
object
- class remoteexec.communicate.sync.SyncInstanceMember(instance_id: int, member_name: str, value: object)¶
ベースクラス:
object
ベースクラス:
object
- remoteexec.communicate.sync.apply_unsirial(target_object: object, sync_object: object, idmap_target_object: dict[int, int] | None = None)¶
- remoteexec.communicate.sync.diff(before_shared_object_serial: object, updated_shared_object_serial: object) SyncSharedObject¶
- remoteexec.communicate.sync.marge(prioritized_object: SyncSharedObject, unprioritized_object: SyncSharedObject) SyncSharedObject¶
Module contents¶
- class remoteexec.communicate.CommunicationIO¶
ベースクラス:
object- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.communicate.CommunicationInterface¶
ベースクラス:
object- init_configure_object(configure_object)¶
- is_alive()¶
- start_command()¶
- stop()¶
- class remoteexec.communicate.Communicator(connection: CommunicationIO, sync_frequency: float, use_compress: bool = True, log_hook: CommunicationLog | None = None)¶
ベースクラス:
object- client(shared_object, configure_object, conflict: ConflictSolvePolicy, snippet_share_only: bool = True, dump_object_depth: int = -1)¶
- host(reciever: CommunicationInterface)¶
- stop()¶
- class remoteexec.communicate.ConflictSolvePolicy(value)¶
ベースクラス:
Enum- CLIENT_PRIORITIZED = 2¶
- HOST_PRIORITIZED = 1¶
- class remoteexec.communicate.UnsirializeFunctionHook¶
ベースクラス:
object- function_call(instanceid: int, name: str, args: tuple, kwargs: dict)¶
remoteexec.hooks package¶
Submodules¶
remoteexec.hooks.hookbase module¶
- class remoteexec.hooks.hookbase.HookBase(targets: List[HookTarget])¶
ベースクラス:
object実行コードに対して定義されるフック関数
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.hookbase.HookTarget(id: int)¶
ベースクラス:
objectフック関数を定義するターゲットのコード
remoteexec.hooks.loophook module¶
- class remoteexec.hooks.loophook.CounterLoopHook(loops: List[HookTarget], maxcount: int)¶
ベースクラス:
LoopHookループ実行回数でループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.loophook.FrequencyLoopHook(loops: List[HookTarget], frequency: float = 0.0)¶
ベースクラス:
LoopHookループ実行周波数でループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.loophook.LoopHook(loops: List[HookTarget])¶
ベースクラス:
HookBaseループ実行に対するフック関数の基底クラス
- clear_loop(id: int)¶
- class remoteexec.hooks.loophook.LoopHookType(value)¶
ベースクラス:
Enumループの種類
- COMP = 3¶
- FOR = 2¶
- WHILE = 1¶
- class remoteexec.hooks.loophook.TimeoutLoopHook(loops: List[HookTarget], timeout: float)¶
ベースクラス:
LoopHookループ実行タイムアウトでループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
remoteexec.hooks.stephook module¶
- class remoteexec.hooks.stephook.StepErrorApproach(value)¶
ベースクラス:
Enum例外発生時の挙動
- DEFAULT = 1¶
- IGNORE_AND_BREAK = 4¶
- IGNORE_AND_CONTINUE = 3¶
- RAISE_ERROR = 2¶
- class remoteexec.hooks.stephook.StepErrorHook(targets: List[HookTarget])¶
ベースクラス:
HookBase一行毎の実行で例外発生時のフック関数の基底クラス
- hook(id: int, lineno: int) StepErrorApproach¶
- class remoteexec.hooks.stephook.StepEvalHook(targets: List[HookTarget])¶
ベースクラス:
StepHook一行毎の実行の実行結果取得フック関数の基底クラス
- hook(id: int, lineno: int, name: str, value: object | None)¶
- class remoteexec.hooks.stephook.StepHook(targets: List[HookTarget])¶
ベースクラス:
HookBase一行毎の実行フック関数の基底クラス
- hook(id: int, lineno: int)¶
- class remoteexec.hooks.stephook.StepTargetHook(targets: List[HookTarget])¶
ベースクラス:
StepHook一行毎の実行のフック関数の基底クラス
- hook(id: int, lineno: int) List[str] | None¶
Module contents¶
- class remoteexec.hooks.CounterLoopHook(loops: List[HookTarget], maxcount: int)¶
ベースクラス:
LoopHookループ実行回数でループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.FrequencyLoopHook(loops: List[HookTarget], frequency: float = 0.0)¶
ベースクラス:
LoopHookループ実行周波数でループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.HookBase(targets: List[HookTarget])¶
ベースクラス:
object実行コードに対して定義されるフック関数
- hook(id: int, lineno: int) Callable¶
- class remoteexec.hooks.HookTarget(id: int)¶
ベースクラス:
objectフック関数を定義するターゲットのコード
- class remoteexec.hooks.LoopHook(loops: List[HookTarget])¶
ベースクラス:
HookBaseループ実行に対するフック関数の基底クラス
- clear_loop(id: int)¶
- class remoteexec.hooks.StepErrorApproach(value)¶
ベースクラス:
Enum例外発生時の挙動
- DEFAULT = 1¶
- IGNORE_AND_BREAK = 4¶
- IGNORE_AND_CONTINUE = 3¶
- RAISE_ERROR = 2¶
- class remoteexec.hooks.StepErrorHook(targets: List[HookTarget])¶
ベースクラス:
HookBase一行毎の実行で例外発生時のフック関数の基底クラス
- hook(id: int, lineno: int) StepErrorApproach¶
- class remoteexec.hooks.StepEvalHook(targets: List[HookTarget])¶
ベースクラス:
StepHook一行毎の実行の実行結果取得フック関数の基底クラス
- hook(id: int, lineno: int, name: str, value: object | None)¶
- class remoteexec.hooks.StepHook(targets: List[HookTarget])¶
ベースクラス:
HookBase一行毎の実行フック関数の基底クラス
- hook(id: int, lineno: int)¶
- class remoteexec.hooks.StepTargetHook(targets: List[HookTarget])¶
ベースクラス:
StepHook一行毎の実行のフック関数の基底クラス
- hook(id: int, lineno: int) List[str] | None¶
- class remoteexec.hooks.TimeoutLoopHook(loops: List[HookTarget], timeout: float)¶
ベースクラス:
LoopHookループ実行タイムアウトでループを制御するフック関数
- clear_loop(id: int)¶
- hook(id: int, lineno: int) Callable¶
remoteexec.inout package¶
Submodules¶
remoteexec.inout.inout module¶
- class remoteexec.inout.inout.ConsoleIO(f1, f2)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.inout.inout.SocketIO(listen_port, listen_addr)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.inout.inout.PipeIO(listen_port, listen_addr)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
Module contents¶
- class remoteexec.inout.ConsoleIO(f1, f2)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.inout.SocketIO(listen_port, listen_addr)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
- class remoteexec.inout.PipeIO(listen_port, listen_addr)¶
ベースクラス:
CommunicationIO- close()¶
- recv(delimiter: bytes = b'\n') bytearray¶
- send(data: bytearray) int¶
Submodules¶
remoteexec.exceptions module¶
- exception remoteexec.exceptions.SnippetAbortException¶
ベースクラス:
SnippetExceptionコード実行の強制中止
- exception remoteexec.exceptions.SnippetCheckError¶
ベースクラス:
SnippetError実行コードチェックの基底クラス
- exception remoteexec.exceptions.SnippetError¶
ベースクラス:
SnippetExceptionエラーの基底クラス
- exception remoteexec.exceptions.SnippetException¶
ベースクラス:
Exception例外の基底クラス
- exception remoteexec.exceptions.SnippetLoopOvertime¶
ベースクラス:
SnippetOvertimeコード実行時のループ処理の実行回数例外
- exception remoteexec.exceptions.SnippetLoopTimeout¶
ベースクラス:
SnippetTimeoutコード実行時のループ処理のタイムアウト例外
- exception remoteexec.exceptions.SnippetOvertime¶
ベースクラス:
SnippetExceptionコード実行時の実行が多すぎる際の例外
- exception remoteexec.exceptions.SnippetProhibitionError¶
ベースクラス:
SnippetCheckError実行コードチェック時の禁則エラー
- exception remoteexec.exceptions.SnippetStepBreak¶
ベースクラス:
SnippetStepErrorStep実行時にIGNORE_AND_BREAKの時のException
- exception remoteexec.exceptions.SnippetStepError¶
ベースクラス:
SnippetExceptionStep実行時にRAISE_ERRORの時のException
- exception remoteexec.exceptions.SnippetSyntaxError¶
ベースクラス:
SnippetCheckError実行コードチェック時の構文エラー
- exception remoteexec.exceptions.SnippetTimeout¶
ベースクラス:
SnippetOvertimeコード実行時のタイムアウト例外
- exception remoteexec.exceptions.SnippetTotalTimeout¶
ベースクラス:
SnippetTimeoutコード実行時の総時間タイムアウト例外
remoteexec.remoteexec module¶
- class remoteexec.remoteexec.RunningConditions(shared_objects: Dict[str, object] | None = None, total_timeout_sec: float = 0, dynamic_import: bool = False, allow_global_functions: List[str] | None = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'complex', 'delattr', 'dict', 'divmod', 'enumerate', 'filter', 'float', 'format', 'frozenset', 'getattr', 'hasattr', 'hash', 'hex', 'id', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'list', 'map', 'max', 'min', 'next', 'object', 'oct', 'ord', 'pow', 'property', 'range', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'], allow_import_modules: List[str] | None = ['string', 're', 'difflib', 'textwrap', 'unicodedata', 'stringprep', 'datetime', 'calendar', 'collections', 'heapq', 'bisect', 'array', 'copy', 'enum', 'numbers', 'math', 'cmath', 'fractions', 'random', 'statistics', 'itertools', 'operator', 'hashlib', 'time', 'json', 'base64'], force_globals: object | None = None, force_locals: object | None = None)¶
ベースクラス:
objectコードの動的実行を行う実行条件を定義するクラス
- パラメータ:
shared_objects (Dict[str,object]) -- コード内変数と共有オブジェクト
total_timeout_sec (float) -- 実行タイムアウト(0以下でタイムアウト無し)
dynamic_import (bool) -- コード内import文を許可する
allow_global_functions (str) -- 利用を許可するPythonビルトイン関数
allow_import_modules (str) -- 予めインポートするPythonパッケージ
force_globals (object) -- globalsを強制的に上書きする(非推奨)
force_locals (object) -- localsを強制的に上書きする(非推奨)
注釈
snippetchecker.support.make_cleaned_builtinsを参照
- class remoteexec.remoteexec.SnippetLoopHook¶
ベースクラス:
object- clear_loop(id: int)¶
- hook(id: int, lineno: int)¶
- class remoteexec.remoteexec.SnippetRunner(local_run: bool = False, docker_run: bool = False, docker_command: List[str] | None = None, tcp_run: bool = False, tcp_hostname: str | None = None, tcp_port: int = 9165, sync_frequency: float = -1, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
ベースクラス:
object- exec(code: str, cond: RunningConditions, frequency: float = -1.0, throttling_mode: bool = True, max_loop_timeout: float = 0.9, max_outer_loop_count: int = -1, max_inner_loop_count: int = -1, includes_comp_loop: bool = True, forced_execution_mode: bool = False, loop_hook: SnippetLoopHook | None = None, step_prefix_hook: SnippetStepHook | None = None, step_postfix_hook: SnippetStepHook | None = None, error_hook: SnippetStepErrorHook | None = None)¶
指定されたコードを実行する
- パラメータ:
code (str) -- 実行コード
cond (RunningConditions) -- 実行条件データ
frequency (float) -- 最も外側のループの最小実行周波数
throttling_mode (bool) -- 周波数に合わせるスロットリングを行うか
max_loop_timeout (float) -- 内側ループの最大実行時間
max_outer_loop_count (int) -- 外側ループの最大実行回数
max_inner_loop_count (int) -- 内側ループの最大実行回数
includes_comp_loop (bool) -- 内包表記([_ for...]など)をループに数える
forced_execution_mode (bool) -- ループを例外発生時に無視して強制実行
loop_hook (SnippetLoopHook) -- ループが実行される度に呼び出されるHook
step_prefix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
step_postfix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
error_hook (SnippetStepErrorHook) -- 実行時Exceptionがraiseした時に呼び出されるHook
注釈
error_hookを指定した場合、エラーハンドリングに例外処理を使うので、 実行コードが例外のraise/catchを行う場合、 StepErrorApproach.DEFAULT以外を渡すと、コードの動作が変わる可能性がある error_hookの戻り値は以下のいずれか StepErrorApproach.DEFAULT: 通常通りの例外を送出 StepErrorApproach.RAISE_ERROR: SnippetStepError例外を送出 StepErrorApproach.IGNORE_AND_CONTINUE: 無視してその場から強引に実行を継続 StepErrorApproach.IGNORE_AND_BREAK: コードブロックの終わりに移動して実行を継続
- run_docker(sync_frequency: float = 5, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
- run_local()¶
- run_tcp(tcp_port: int = 9165, sync_frequency: float = 5, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
- class remoteexec.remoteexec.SnippetRunnerLocal¶
ベースクラス:
object- exec(code: str, cond: RunningConditions, features: List[RunningFeatureBase] | None = None)¶
指定されたコードをローカル実行環境で実行する
- パラメータ:
code (str) -- 実行コード
cond (RunningConditions) -- 実行条件データ
features (List[RunningFeatureBase]) -- 利用するFeatures
- class remoteexec.remoteexec.SnippetRunnerRemote(connection: CommunicationIO, sync_frequency: float = 5, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
ベースクラス:
object- exec(code: str, cond: RunningConditions, frequency: float = -1.0, throttling_mode: bool = True, max_loop_timeout: float = 0.9, max_outer_loop_count: int = -1, max_inner_loop_count: int = -1, includes_comp_loop: bool = True, forced_execution_mode: bool = False, loop_hook: SnippetLoopHook | None = None, step_prefix_hook: SnippetStepHook | None = None, step_postfix_hook: SnippetStepHook | None = None, error_hook: SnippetStepErrorHook | None = None)¶
指定されたコードをリモート実行環境で実行する
- パラメータ:
code (str) -- 実行コード
cond (RunningConditions) -- 実行条件データ
frequency (float) -- 最も外側のループの最小実行周波数
throttling_mode (bool) -- 周波数に合わせるスロットリングを行うか
max_loop_timeout (float) -- 内側ループの最大実行時間
max_outer_loop_count (int) -- 外側ループの最大実行回数
max_inner_loop_count (int) -- 内側ループの最大実行回数
includes_comp_loop (bool) -- 内包表記([_ for...]など)をループに数える
forced_execution_mode (bool) -- ループを例外発生時に無視して強制実行
loop_hook (SnippetLoopHook) -- ループが実行される度に呼び出されるHook
step_prefix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
step_postfix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
error_hook (SnippetStepErrorHook) -- 実行時Exceptionがraiseした時に呼び出されるHook
注釈
error_hookを指定した場合、エラーハンドリングに例外処理を使うので、 実行コードが例外のraise/catchを行う場合、 StepErrorApproach.DEFAULT以外を渡すと、コードの動作が変わる可能性がある error_hookの戻り値は以下のいずれか StepErrorApproach.DEFAULT: 通常通りの例外を送出 StepErrorApproach.RAISE_ERROR: SnippetStepError例外を送出 StepErrorApproach.IGNORE_AND_CONTINUE: 無視してその場から強引に実行を継続 StepErrorApproach.IGNORE_AND_BREAK: コードブロックの終わりに移動して実行を継続
- class remoteexec.remoteexec.SnippetStepErrorHook¶
ベースクラス:
object- hook(id: int, lineno: int) StepErrorApproach¶
remoteexec.runnerfeature module¶
- class remoteexec.runnerfeature.RunningFeatureBase¶
ベースクラス:
objectSnippetRunnerの実行時に利用するFeatureを定義するBaseクラス
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
- class remoteexec.runnerfeature.RunningWithEvalCheck(target_hook_class: object = <class 'remoteexec.hooks.stephook.StepTargetHook'>, eval_hook_class: object = <class 'remoteexec.hooks.stephook.StepEvalHook'>)¶
ベースクラス:
RunningFeatureBasePythonコードの1ステップ毎に変数をチェックするデバッグ用Feature target_hook_classのHookの戻り値でチェックする変数を指定できる チェックする変数はその後に呼び出されるeval_hook_classに渡される
サンプル
>>> class MyStepTargetHook(StepTargetHook): >>> def hook(self, id:int, lineno:int) -> Optional[List[str]]: >>> return ["target"] if lineno==2 or lineno==4 else None >>> class MyStepEvalHook(StepEvalHook): >>> def hook(self, id:int, lineno:int, name:str, value:Optional[object]): >>> print(f"StepEvalHook -- lineno={lineno} name={name} value={value}") >>> feature = RunningWithEvalCheck(target_hook_class=MyStepTargetHook, >>> eval_hook_class=MyStepEvalHook) >>> code = '''target = "abcde" >>> print('start') >>> print(target:='fghij') >>> print('end') >>> ''' >>> runner = SnippetRunnerLocal() >>> hook_return_code = StepErrorApproach.IGNORE_AND_CONTINUE >>> runner.exec(code, cond=RunningConditions(), features=[feature]) start StepEvalHook -- lineno=2 name=target value=abcde fghij end StepEvalHook -- lineno=4 name=target value=fghij
注釈
変数チェックにevalを使用するので、allow_global_functionsにevalを追加する必要がある その事によりセキュリティリスクが発生するので、このFeatureはデバッグのためにのみ使う事
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
- class remoteexec.runnerfeature.RunningWithIgnoreError(error_approach: StepErrorApproach = StepErrorApproach.DEFAULT)¶
ベースクラス:
RunningWithSteppingCheckPythonコードを1ステップ毎に実行しエラーをチェックする error_approachでエラーの時の実行方針を設定できる StepErrorApproach.DEFAULT: 通常通りの例外を送出 StepErrorApproach.RAISE_ERROR: SnippetStepError例外を送出 StepErrorApproach.IGNORE_AND_CONTINUE: 無視してその場から強引に実行を継続 StepErrorApproach.IGNORE_AND_BREAK: コードブロックの終わりに移動して実行を継続
- パラメータ:
error_approach (StepErrorApproach) -- エラー発生時の対処法
サンプル
>>> feature = RunningWithIgnoreError(StepErrorApproach.IGNORE_AND_CONTINUE) >>> code = '''for i in range(3): >>> print('start') >>> print(100 / 0) # raise error >>> print('end') >>> ''' >>> runner = SnippetRunnerLocal() >>> runner.exec(code, cond=RunningConditions(), features=[feature]) start end start end start end >>> feature = RunningWithIgnoreError(StepErrorApproach.IGNORE_AND_BREAK) >>> runner.exec(code, cond=RunningConditions(), features=[feature]) start start start
注釈
エラーハンドリングに例外処理を使うので、実行コードが例外のraise/catchを行う場合、 StepErrorApproach.DEFAULT以外を渡すと、コードの動作が変わる可能性がある
- class remoteexec.runnerfeature.RunningWithLoopHook(hook_classes: ~typing.List[object] = [<class 'remoteexec.hooks.loophook.LoopHook'>], includes_comp_loop: bool = True, forced_execution_mode: bool = False)¶
ベースクラス:
RunningFeatureBaseループの実行にHookを入れるFeature
- パラメータ:
hook_classes (List[LoopHook]) -- list of LoopHook
includes_comp_loop (bool) -- 内包表記([_ for...]など)をループに数える
forced_execution_mode (bool) -- ループを強制執行モードで実行
サンプル
hook_classesにLoopHookクラスを指定するとループ時にHookする
>>> class MyCounterLoopHook(CounterLoopHook): >>> def __init__(self, loops:List[HookTarget]): >>> super().__init__(loops=loops, maxcount=5) >>> feature = RunningWithLoopHook([MyCounterLoopHook], forced_execution_mode=True) >>> code = '''for i in range(500): >>> print('hoge') >>> ''' >>> runner = SnippetRunnerLocal() >>> runner.exec(code, cond=RunningConditions(), features=[feature]) >>> print("end") hoge hoge hoge hoge hoge end
注釈
forced_execution_modeがTrueのとき、FOR、WHILEなら強引に処理を続ける
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
- class remoteexec.runnerfeature.RunningWithOuterFrequency(frequency: float = -1.0, throttling_mode: bool = True, max_loop_timeout: float = 0.9, max_outer_loop_count: int = -1, max_inner_loop_count: int = -1, includes_comp_loop: bool = True, forced_execution_mode: bool = False)¶
ベースクラス:
RunningWithLoopHook最も外側のループの実行周波数を指定してコードを実行するFeature 外側のループはFORとWHILEのみで、複数あるときは全てに周波数を適用 ループ内ループの場合に、内側ループのタイムアウト処理を指定できる
- パラメータ:
frequency (float) -- 最も外側のループの最小実行周波数
throttling_mode (bool) -- 周波数に合わせるスロットリングを行うか
max_loop_timeout (float) -- 内側ループの最大実行時間
max_outer_loop_count (int) -- 外側ループの最大実行回数
max_inner_loop_count (int) -- 内側ループの最大実行回数
includes_comp_loop (bool) -- 内包表記([_ for...]など)をループに数える
forced_execution_mode (bool) -- ループを例外発生時に無視して強制実行
サンプル
frequencyを指定して実行するとその周波数で実行される
>>> feature = RunningWithOuterFrequency(frequency=50) >>> code = '''for i in range(500): >>> if i%100==0: >>> print('hoge') >>> ''' >>> runner = SnippetRunnerLocal() >>> start_time = time.time() >>> runner.exec(code, cond=RunningConditions(), features=[feature]) hoge hoge hoge hoge hoge >>> print(round(time.time() - start_time)) 10
注釈
frequency<=0なら周波数制御は行わない(スロットリング最大) frequencyとthrottling_modeのどちらかは指定する必要がある max_outer_loop_count、max_inner_loop_count<0は無限ループを許可 forced_execution_modeがTrueのとき、FOR、WHILEなら、実行回数オーバー、 タイムアウト時に例外を送出せず、ループを強制中断して強引に処理を続ける
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
- class remoteexec.runnerfeature.RunningWithSteppingCheck(prefix_hook_class: object = <class 'remoteexec.hooks.stephook.StepHook'>, postfix_hook_class: object = <class 'remoteexec.hooks.stephook.StepHook'>, error_hook_class: object = <class 'remoteexec.hooks.stephook.StepErrorHook'>)¶
ベースクラス:
RunningFeatureBasePythonコードを1ステップ毎に実行しHookを実行する error_hook_classのHookの戻り値でエラーの時の実行方針を設定できる
- パラメータ:
prefix_hook_class (StepHook) -- 1ステップ実行前のHook
postfix_hook_class (StepHook) -- 1ステップ実行後のHook
error_hook_class (StepErrorHook) -- エラー時のHook
サンプル
>>> hook_return_code = StepErrorApproach.DEFAULT >>> class MyPrefixHook(StepHook): >>> def hook(self, id:int, lineno:int): >>> print(f"MyPrefixHook - {lineno}") >>> class MyPostfixHook(StepHook): >>> def hook(self, id:int, lineno:int): >>> print(f"MyPostfixHook - {lineno}") >>> feature = RunningWithSteppingCheck(prefix_hook_class=MyPrefixHook, postfix_hook_class=MyPostfixHook) >>> code = '''print('A') >>> print('B') >>> print('C') >>> ''' >>> runner = SnippetRunnerLocal() >>> hook_return_code = StepErrorApproach.IGNORE_AND_CONTINUE >>> runner.exec(code, cond=RunningConditions(), features=[feature]) MyPrefixHook - 1 A MyPostfixHook - 1 MyPrefixHook - 2 B MyPostfixHook - 2 MyPrefixHook - 3 C MyPostfixHook - 3
注釈
エラーハンドリングに例外処理を使うので、実行コードが例外のraise/catchを行う場合、 StepErrorApproach.DEFAULT以外を返すと、コードの動作が変わる可能性がある
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
- class remoteexec.runnerfeature.RunningWithoutImport¶
ベースクラス:
RunningFeatureBaseimport文を除去する
- update_tree(root: AST, ext_objects: Dict[str, object] | None)¶
Module contents¶
- class remoteexec.ConflictSolvePolicy(value)¶
ベースクラス:
Enum- CLIENT_PRIORITIZED = 2¶
- HOST_PRIORITIZED = 1¶
- class remoteexec.RunningConditions(shared_objects: Dict[str, object] | None = None, total_timeout_sec: float = 0, dynamic_import: bool = False, allow_global_functions: List[str] | None = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'complex', 'delattr', 'dict', 'divmod', 'enumerate', 'filter', 'float', 'format', 'frozenset', 'getattr', 'hasattr', 'hash', 'hex', 'id', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'list', 'map', 'max', 'min', 'next', 'object', 'oct', 'ord', 'pow', 'property', 'range', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'], allow_import_modules: List[str] | None = ['string', 're', 'difflib', 'textwrap', 'unicodedata', 'stringprep', 'datetime', 'calendar', 'collections', 'heapq', 'bisect', 'array', 'copy', 'enum', 'numbers', 'math', 'cmath', 'fractions', 'random', 'statistics', 'itertools', 'operator', 'hashlib', 'time', 'json', 'base64'], force_globals: object | None = None, force_locals: object | None = None)¶
ベースクラス:
objectコードの動的実行を行う実行条件を定義するクラス
- パラメータ:
shared_objects (Dict[str,object]) -- コード内変数と共有オブジェクト
total_timeout_sec (float) -- 実行タイムアウト(0以下でタイムアウト無し)
dynamic_import (bool) -- コード内import文を許可する
allow_global_functions (str) -- 利用を許可するPythonビルトイン関数
allow_import_modules (str) -- 予めインポートするPythonパッケージ
force_globals (object) -- globalsを強制的に上書きする(非推奨)
force_locals (object) -- localsを強制的に上書きする(非推奨)
注釈
snippetchecker.support.make_cleaned_builtinsを参照
- class remoteexec.SnippetRunner(local_run: bool = False, docker_run: bool = False, docker_command: List[str] | None = None, tcp_run: bool = False, tcp_hostname: str | None = None, tcp_port: int = 9165, sync_frequency: float = -1, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
ベースクラス:
object- exec(code: str, cond: RunningConditions, frequency: float = -1.0, throttling_mode: bool = True, max_loop_timeout: float = 0.9, max_outer_loop_count: int = -1, max_inner_loop_count: int = -1, includes_comp_loop: bool = True, forced_execution_mode: bool = False, loop_hook: SnippetLoopHook | None = None, step_prefix_hook: SnippetStepHook | None = None, step_postfix_hook: SnippetStepHook | None = None, error_hook: SnippetStepErrorHook | None = None)¶
指定されたコードを実行する
- パラメータ:
code (str) -- 実行コード
cond (RunningConditions) -- 実行条件データ
frequency (float) -- 最も外側のループの最小実行周波数
throttling_mode (bool) -- 周波数に合わせるスロットリングを行うか
max_loop_timeout (float) -- 内側ループの最大実行時間
max_outer_loop_count (int) -- 外側ループの最大実行回数
max_inner_loop_count (int) -- 内側ループの最大実行回数
includes_comp_loop (bool) -- 内包表記([_ for...]など)をループに数える
forced_execution_mode (bool) -- ループを例外発生時に無視して強制実行
loop_hook (SnippetLoopHook) -- ループが実行される度に呼び出されるHook
step_prefix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
step_postfix_hook (SnippetStepHook) -- 1ステップ実行される度に呼び出されるHook
error_hook (SnippetStepErrorHook) -- 実行時Exceptionがraiseした時に呼び出されるHook
注釈
error_hookを指定した場合、エラーハンドリングに例外処理を使うので、 実行コードが例外のraise/catchを行う場合、 StepErrorApproach.DEFAULT以外を渡すと、コードの動作が変わる可能性がある error_hookの戻り値は以下のいずれか StepErrorApproach.DEFAULT: 通常通りの例外を送出 StepErrorApproach.RAISE_ERROR: SnippetStepError例外を送出 StepErrorApproach.IGNORE_AND_CONTINUE: 無視してその場から強引に実行を継続 StepErrorApproach.IGNORE_AND_BREAK: コードブロックの終わりに移動して実行を継続
- run_docker(sync_frequency: float = 5, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
- run_local()¶
- run_tcp(tcp_port: int = 9165, sync_frequency: float = 5, sync_conflict_policy: ConflictSolvePolicy = ConflictSolvePolicy.HOST_PRIORITIZED, sync_snippet_share_only: bool = True, sync_shared_depth: int = -1)¶
- class remoteexec.SnippetRunnerLocal¶
ベースクラス:
object- exec(code: str, cond: RunningConditions, features: List[RunningFeatureBase] | None = None)¶
指定されたコードをローカル実行環境で実行する
- パラメータ:
code (str) -- 実行コード
cond (RunningConditions) -- 実行条件データ
features (List[RunningFeatureBase]) -- 利用するFeatures
- class remoteexec.SnippetStepErrorHook¶
ベースクラス:
object- hook(id: int, lineno: int) StepErrorApproach¶