From 5dd19a184ba89accfd82c0d01a17bdb228fda030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Thu, 12 Sep 2024 08:44:16 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8A=9F=E8=83=BD=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/service/client.py | 17 +++++++---------- test/service/server.py | 8 +++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/test/service/client.py b/test/service/client.py index 4d239e7..034ff4f 100644 --- a/test/service/client.py +++ b/test/service/client.py @@ -1,19 +1,16 @@ -import requests -URL = "http://192.168.230.132:8011" code = """ import time +import os print("hello world") -cnt = 0 -while True: - print(cnt) - cnt += 1 - time.sleep(0.1) - +print(os.environ) """ -resp = requests.post(URL, json={"code": code}) -print(resp.json()["msg"]) +if __name__ == "__main__": + import requests + url = "http://127.0.0.1:8011" + resp = requests.post(url, json={"code": code}) + print(resp.json()["msg"]) diff --git a/test/service/server.py b/test/service/server.py index 2de20ca..9518c66 100644 --- a/test/service/server.py +++ b/test/service/server.py @@ -4,8 +4,10 @@ import os import subprocess import time + app = Flask(__name__) -ROCKER_PATH = "/home/yanguangshaonian/rocker/target/debug/rocker" +USER_NAME = "ubuntu" +ROCKER_PATH = f"/home/{USER_NAME}/rocker/target/debug/rocker" @app.route("/", methods=["POST"]) def hello_world(): @@ -21,7 +23,7 @@ def hello_world(): "--id", _id, "--image", "ubuntu_pypy_numpy_pandas_user", "--run", "python -u /tmp/main.py", - "--env", "/home/yanguangshaonian/rocker/pypy.env", + "--env", f"/home/{USER_NAME}/rocker/pypy.env", "--volume", f"{user_path}:/tmp", "--log"]) except Exception as e: @@ -45,4 +47,4 @@ def hello_world(): return {"msg": out, code: code, "id": _id} if __name__ == "__main__": - app.run(host='0.0.0.0', port=8011) \ No newline at end of file + app.run(host='0.0.0.0', port=8011, threaded=True) \ No newline at end of file