Kaynağa Gözat

改变穷举进程模式,多策略但完整stock_list运算,分段计算,避免溢出

daniel 2 yıl önce
ebeveyn
işleme
61bee63e87
1 değiştirilmiş dosya ile 9 ekleme ve 6 silme
  1. 9 6
      futures_backtrader.py

+ 9 - 6
futures_backtrader.py

@@ -237,7 +237,7 @@ if __name__ == '__main__':
     cursor.execute("show tables like '%%%s%%' " % fre)
     table_list = [tuple[0] for tuple in cursor.fetchall()]
     # print(table_list)
-    # table_list = table_list[0:100]
+    table_list = table_list[0:100]
 
     mgr = Manager()
     ns = mgr.Namespace()
@@ -247,7 +247,7 @@ if __name__ == '__main__':
     sttime = dt.now()
     thread_list = []
     for num in range(30, 120, 10):
-        for Volatility in range(3, 21, 1):
+        for Volatility in range(10, 21, 1):
             for rate in range(5, 15, 1):
                 #获得cpu数量,计算进程数
                 # step = math.ceil(len(table_list)/cpu_count/100)*100
@@ -262,10 +262,13 @@ if __name__ == '__main__':
                     # p.join()
     print(len(thread_list))
     print('开始轮循!')
-    for thread in thread_list:
-        thread.start()
-    for thread in thread_list:
-        thread.join()
+    step = int(len(thread_list)/cpu_count)
+    thread_list_b = [thread_list[i:i+step] for i in range(0, len(thread_list), step)]
+    for t_list in thread_list_b:
+        for thread in t_list:
+            thread.start()
+        for thread in t_list:
+            thread.join()
     print('NS.DF:', '\n', ns.df)
     edtime = dt.now()
     print('总耗时:', edtime - sttime)