Эх сурвалжийг харах

!2 use thread pool to limit thread count 1

pcacc 5 сар өмнө
parent
commit
a19298e35f

+ 11 - 1
app_dongri.py

@@ -9,6 +9,10 @@ import threading
 from dongri_task import *
 from dongri_task import *
 from collections import deque
 from collections import deque
 import json
 import json
+from concurrent.futures import ThreadPoolExecutor
+
+# 全局线程池,限制最大线程数为1
+executor = ThreadPoolExecutor(max_workers=1)
 
 
 app = Flask(__name__)
 app = Flask(__name__)
 socketio = SocketIO(app)
 socketio = SocketIO(app)
@@ -126,7 +130,7 @@ def handle_restart_game():
     os.execl(python, python, *sys.argv, '--reset')
     os.execl(python, python, *sys.argv, '--reset')
 
 
 def restart_game():
 def restart_game():
-    global isGameBegin, autoTask
+    global isGameBegin
     isGameBegin = False
     isGameBegin = False
     while True:
     while True:
         task_close_game()
         task_close_game()
@@ -208,17 +212,23 @@ def auto_task(data):
     else:
     else:
         isMaxCollect = data['maxCollect']
         isMaxCollect = data['maxCollect']
     send_status(f'开始自动模式')
     send_status(f'开始自动模式')
+    executor.submit(add_auto_task, isMaxCollect)
+    '''
     autoTask = threading.Thread(target=add_auto_task, args=(isMaxCollect,))#启动线程往里面添加任务
     autoTask = threading.Thread(target=add_auto_task, args=(isMaxCollect,))#启动线程往里面添加任务
     autoTask.daemon = True
     autoTask.daemon = True
     autoTask.start()
     autoTask.start()
+    '''
 
 
 @socketio.on('begin_auto_participate')
 @socketio.on('begin_auto_participate')
 def handle_auto_participate():
 def handle_auto_participate():
     global autoTask
     global autoTask
     send_status(f'开始自动集结模式')
     send_status(f'开始自动集结模式')
+    executor.submit(auto_participate)
+    '''
     autoTask = threading.Thread(target=auto_participate)#启动线程往里面添加任务
     autoTask = threading.Thread(target=auto_participate)#启动线程往里面添加任务
     autoTask.daemon = True
     autoTask.daemon = True
     autoTask.start()
     autoTask.start()
+    '''
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':

+ 1 - 1
scriptBase/comon.py

@@ -225,7 +225,7 @@ def find_window_pos(title):
     height = window.height
     height = window.height
 
 
     # 打印位置信息
     # 打印位置信息
-    print(f'Left: {left}, Top: {top}, Width: {width}, Height: {height}')
+    #print(f'Left: {left}, Top: {top}, Width: {width}, Height: {height}')
     if left > 0 and top > 0 and width > 0 and height > 0:
     if left > 0 and top > 0 and width > 0 and height > 0:
         return True, (left, top, width, height)
         return True, (left, top, width, height)
     else:
     else: