Ver Fonte

fix: 与commitId解耦合

haha há 3 anos atrás
pai
commit
f119fd51a1
1 ficheiros alterados com 6 adições e 4 exclusões
  1. 6 4
      web/app.py

+ 6 - 4
web/app.py

@@ -1,5 +1,6 @@
 # encoding: utf8
 import os
+import random
 import shutil
 import time
 
@@ -33,7 +34,6 @@ def judge():
     data = json.loads(requestData)
     code = data['code']
     language = data['language']
-    cid = str(data['commitId'])
     time_limit = int(data['timeLimit'])
     memory_limit = int(data['memoryLimit'])
     input_list = data['inputList']
@@ -42,9 +42,11 @@ def judge():
     app_path = os.getcwd()
     app.logger.info(app_path)
 
-    dir_name = 'commit-' + cid
-    if os.path.exists(dir_name):
-        shutil.rmtree(dir_name)
+    rand = int(random.random() * 10000000)
+    dir_name = 'commit-' + str(rand)
+    while os.path.exists(dir_name):
+        rand = rand+1
+        dir_name = 'commit-' + str(rand)
     os.mkdir(dir_name)
     os.chdir(app_path+'/'+dir_name)
     app.logger.info(os.getcwd())