| 267 | |
| 268 | @tvm_ffi.register_global_func("rpc.PopenSession") |
| 269 | def _popen_session(binary): |
| 270 | temp = utils.tempdir() |
| 271 | |
| 272 | if isinstance(binary, bytes | bytearray): |
| 273 | path_exec = temp.relpath("server.minrpc") |
| 274 | with open(path_exec, "wb") as outfile: |
| 275 | outfile.write(binary) |
| 276 | os.chmod(path_exec, stat.S_IXUSR | stat.S_IRUSR) |
| 277 | path_exec = os.path.abspath(path_exec) |
| 278 | else: |
| 279 | path_exec = os.path.abspath(binary) |
| 280 | if not os.path.isfile(path_exec): |
| 281 | raise RuntimeError(f"{path_exec} does not exist.") |
| 282 | if not os.access(path_exec, os.X_OK): |
| 283 | raise RuntimeError(f"{path_exec} is not executable.") |
| 284 | |
| 285 | sess = _ffi_api.CreatePipeClient(path_exec) |
| 286 | return sess |
| 287 | |
| 288 | |
| 289 | class PopenSession(RPCSession): |