通过Flask python服务器和libcurl C ++侦听器的连接失败

时间:2019-03-04 14:52:23

标签: python-3.x curl flask

我正在通过openAI gym中的http连接使用C++(由python开发),该连接在 [https://github.com/openai/gym-http-api/tree/master][1]。通过调用使用gym_http_server.py的{​​{1}}创建服务器,并且Flask代码使用C++发布并获取结果,该结果位于libcurl目录中。

当我通过cpp-binding调用python服务器时,curl失败并显示以下错误: python3 gym_http_server.py 经过几百次发布。它发生在curle_couldnt_connect函数中:

POST

被称为 Json::Value POST(const std::string& route, const std::string& post_data) { std::string url = "http://" + addr + route; if (verbose) printf("POST %s\n%s\n", url.c_str(), post_data.c_str()); curl_easy_setopt(h.get(), CURLOPT_URL, url.c_str()); curl_easy_setopt(h.get(), CURLOPT_PORT, port); std::string answer; curl_easy_setopt(h.get(), CURLOPT_WRITEDATA, &answer); curl_easy_setopt(h.get(), CURLOPT_POST, 1); curl_easy_setopt(h.get(), CURLOPT_POSTFIELDS, post_data.c_str()); curl_easy_setopt(h.get(), CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)post_data.size()); curl_easy_setopt(h.get(), CURLOPT_HTTPHEADER, headers.get()); CURLcode r = curl_easy_perform(h.get()); if (r) throw std::runtime_error(curl_error_buf.data()); Json::Value j; throw_server_error_or_response_code(answer, j); return j; } ,都可以在“ gym_binding.cpp”中找到。

我还监视了Json::Value ans = client->POST("/v1/envs/" + instance_id + "/step/", act_json.toStyledString());memory的{​​{1}}和cpu用法,发现任何异常现象。 另外,还有一个观察,由于某种原因,我不得不重新启动服务器,此后它可以正常工作一天半,尽管之后它又再次停止工作。

然后,奇怪的一点是,当我通过python调用python服务器时,它是python调试器,一切正常。我开始C++来发现pudb3 gym_http_server.py服务器可能存在的问题,并发现了这一现象。显然,pudbFlask慢(就执行相同代码的CPU时间而言),但是我不明白观察的原因。

考虑到这种情况,我认为可能有一些设置可用于配置pudb,以便它可以与常规的python调用而不是Flask一起使用。感谢您的帮助或评论。

0 个答案:

没有答案