服务功能更新

main
阳光少年 1 year ago
parent dc3fc432b5
commit 5dd19a184b

@ -1,19 +1,16 @@
import requests
URL = "http://192.168.230.132:8011"
code = """ code = """
import time import time
import os
print("hello world") print("hello world")
cnt = 0 print(os.environ)
while True:
print(cnt)
cnt += 1
time.sleep(0.1)
""" """
resp = requests.post(URL, json={"code": code}) if __name__ == "__main__":
import requests
url = "http://127.0.0.1:8011"
resp = requests.post(url, json={"code": code})
print(resp.json()["msg"]) print(resp.json()["msg"])

@ -4,8 +4,10 @@ import os
import subprocess import subprocess
import time import time
app = Flask(__name__) 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"]) @app.route("/", methods=["POST"])
def hello_world(): def hello_world():
@ -21,7 +23,7 @@ def hello_world():
"--id", _id, "--id", _id,
"--image", "ubuntu_pypy_numpy_pandas_user", "--image", "ubuntu_pypy_numpy_pandas_user",
"--run", "python -u /tmp/main.py", "--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", "--volume", f"{user_path}:/tmp",
"--log"]) "--log"])
except Exception as e: except Exception as e:
@ -45,4 +47,4 @@ def hello_world():
return {"msg": out, code: code, "id": _id} return {"msg": out, code: code, "id": _id}
if __name__ == "__main__": if __name__ == "__main__":
app.run(host='0.0.0.0', port=8011) app.run(host='0.0.0.0', port=8011, threaded=True)
Loading…
Cancel
Save