Error in curl::curl_fetch_memory(url, handle = handle) : Failed to connect to 127.0.0.1 port 5000: Connection refused

Viewed 1850

I'm developing an R package, which contains the following function:

#' @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)
}

The python script I call can be found here: https://github.com/openai/gym-http-api/blob/master/gym_http_server.py

When I start RStudio, load the package and run makeEnvironment("MountainCar-v0") I get the error

Error in curl::curl_fetch_memory(url, handle = handle) : Failed to connect to 127.0.0.1 port 5000: Connection refused

which is caused by gym::env_create(private$client, name). If I just repeat makeEnvironment("MountainCar-v0") again, it works fine.

Can someone help? Why do I get this error and how to fix this?

Session Info

R version 3.4.1 (2017-06-30) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale: [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

attached base packages: [1] stats graphics grDevices utils
datasets methods base

other attached packages: [1] reinforcelearn_0.0.0.9070

loaded via a namespace (and not attached): [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.1 checkmate_1.8.3 jsonlite_1.5
[13] gym_0.1.0 linprog_0.9-2 lattice_0.20-35

0 Answers
Related