Commit 5cab7ab1 authored by Yuan Zhixiang's avatar Yuan Zhixiang
Browse files

修复 kill任务时临时文件夹不会被删除的bug

parent cfb78256
...@@ -6,6 +6,8 @@ from gevent.pywsgi import WSGIServer ...@@ -6,6 +6,8 @@ from gevent.pywsgi import WSGIServer
from flask_cors import CORS from flask_cors import CORS
import psutil import psutil
import signal import signal
import os
import shutil
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
...@@ -68,9 +70,20 @@ def run_python2_script_and_get_output(code, stdin): ...@@ -68,9 +70,20 @@ def run_python2_script_and_get_output(code, stdin):
for child in children: for child in children:
child.send_signal(signal.SIGKILL) child.send_signal(signal.SIGKILL)
process.send_signal(signal.SIGKILL) process.send_signal(signal.SIGKILL)
remove_random_temp_folders()
return 'timeout' return 'timeout'
# 移除 run_cpp_backend.py 创建的随机临时文件夹
def remove_random_temp_folders():
for item in os.listdir('.'):
if os.path.isdir(item) and len(item) == 36:
try:
shutil.rmtree(item)
except Exception as remove_random_temp_folders_e:
print(remove_random_temp_folders_e)
if __name__ == '__main__': if __name__ == '__main__':
print('c-backend server start.') print('c-backend server start.')
r = redis.Redis(host='c-redis-service', password='c-backend', port=6379, decode_responses=True) r = redis.Redis(host='c-redis-service', password='c-backend', port=6379, decode_responses=True)
...@@ -78,8 +91,8 @@ if __name__ == '__main__': ...@@ -78,8 +91,8 @@ if __name__ == '__main__':
r.ping() r.ping()
redis_available = True redis_available = True
print('redis: connected.') print('redis: connected.')
except redis.exceptions.ConnectionError as e: except redis.exceptions.ConnectionError as redis_e:
print('redis: failed.', e) print('redis: failed.', redis_e)
# 启动后端 # 启动后端
http_server = WSGIServer(('', 5000), app) http_server = WSGIServer(('', 5000), app)
http_server.serve_forever() http_server.serve_forever()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment