curl::curl_fetch_memory(url, handle = handle) 中的错误:无法连接到 127.0.0.1 端口 5000:连接被拒绝

nee*_*elp 5 r

我正在开发一个 R 包,其中包含以下功能:

#' @export
makeEnvironment = function(name) {
  envir = R6::R6Class(
    public = list(
      initialize = function(name) {
        remote.base = "http://127.0.0.1:5000"
        private$client = gym::create_GymClient(remote.base)
        private$instance.id = gym::env_create(private$client, name)
        outdir = "/tmp/random-agent-results"
        gym::env_monitor_start(private$client, private$instance.id, outdir, 
          force = TRUE, resume = FALSE)
        print(gym::env_action_space_info(private$client, private$instance.id))
      }
    ),
    private = list(
      client = NULL,
      instance.id = NULL
    )
  )
  package.path = system.file(package = "reinforcelearn")
  path2pythonfile = paste0(package.path, "/gym_http_server.py")
  system2("python", args = path2pythonfile, stdout = NULL, wait = FALSE)
  envir$new(name)
}
Run Code Online (Sandbox Code Playgroud)

我调用的python脚本可以在这里找到:https : //github.com/openai/gym-http-api/blob/master/gym_http_server.py

当我启动 RStudio 时,加载包并运行makeEnvironment("MountainCar-v0")我收到错误

curl::curl_fetch_memory(url, handle = handle) 中的错误:无法连接到 127.0.0.1 端口 5000:连接被拒绝

这是由gym::env_create(private$client, name). 如果我再重复一遍makeEnvironment("MountainCar-v0"),它工作正常。

有人可以帮忙吗?为什么会出现此错误以及如何解决此问题?

会议信息

R 版本 3.4.1 (2017-06-30) 平台:x86_64-w64-mingw32/x64 (64-bit) 运行环境:Windows >= 8 x64 (build 9200)

矩阵产品:默认

语言环境:[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 [4] LC_NUMERIC=C LC_TIME=German_Germany.1252

附加的基础包:[1] 统计图形 grDevices utils
数据集方法基础

其他附加包:[1] 强化学习_0.0.0.9070

通过命名空间加载(且未附加):[1] httr_1.2.1
compiler_3.4.1 backports_1.1.0 R6_2.2.2 Matrix_1.2-10
tools_3.4.1 [7] nnet_7.3-12 curl_2.8.1
MDPtoolbox_4.0.3 grid_3.4.4. checkmate_1.8.3 jsonlite_1.5
[13] 健身房_0.1.0 linprog_0.9-2 格子_0.20-35