From cc6fcdf8e3792d17ccf436fb2f03fcda57b0f06a Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 15 八月 2023 17:11:28 +0800
Subject: [PATCH] ++++++++++++++++ bug修复-

---
 main.py                          |   15 +++++++
 log_module/log.py                |    7 ++-
 trade/huaxin/trade_api_server.py |   64 +++++++++-----------------------
 3 files changed, 37 insertions(+), 49 deletions(-)

diff --git a/log_module/log.py b/log_module/log.py
index 3594117..bf72c8c 100644
--- a/log_module/log.py
+++ b/log_module/log.py
@@ -1,6 +1,7 @@
 """
 鏃ュ織
 """
+import logging
 import os
 import sys
 from loguru import logger
@@ -293,5 +294,7 @@
 
 
 def close_print():
-    os.close(1)
-    os.open('/dev/null', os.O_WRONLY)
+    logging.basicConfig(level=logging.ERROR)
+    if not constant.is_windows():
+        os.close(1)
+        os.open('/dev/null', os.O_WRONLY)
diff --git a/main.py b/main.py
index fdcd686..6fbd764 100644
--- a/main.py
+++ b/main.py
@@ -59,6 +59,19 @@
 
 
 if __name__ == '__main__':
+    st1 = "#"
+    for i in range(1000):
+        st1 += "#"
+    st2 = "#"
+    for i in range(10000):
+        st2 += "#"
+
+    start_time = time.time()
+    print(st1)
+    print("鑰楁椂1锛�", time.time() - start_time)
+    start_time = time.time()
+    print(st2)
+    print("鑰楁椂2锛�", time.time() - start_time)
     log.close_print()
     # 绛栫暐涓巗erver闂寸殑閫氫俊
     pss_server, pss_strategy = multiprocessing.Pipe()
@@ -85,7 +98,7 @@
     l2Process = multiprocessing.Process(target=huaxin_api.l2_client.run, args=(ptl2_l2, psl2_l2,))
     l2Process.start()
     #
-    tradeProcess = multiprocessing.Process(target=huaxin_api.trade_client.run,args=(ptl2_trade, pst_trade,))
+    tradeProcess = multiprocessing.Process(target=huaxin_api.trade_client.run, args=(ptl2_trade, pst_trade,))
     tradeProcess.start()
     # L1璁㈤槄鏁版嵁
     huaxin_api.l1_client.run_async(pl1t_l1)
diff --git a/trade/huaxin/trade_api_server.py b/trade/huaxin/trade_api_server.py
index 72c01fa..bb16576 100644
--- a/trade/huaxin/trade_api_server.py
+++ b/trade/huaxin/trade_api_server.py
@@ -420,58 +420,30 @@
         super().finish()
 
 
-test_data = [('600829', 60024, 8.33), ('603610', 40000, 12.5), ('002945', 28474, 17.56), ('600689', 47438, 10.54),
-             ('002907', 26288, 19.02), ('002999', 60680, 8.24), ('601136', 18939, 26.4), ('603190', 16062, 31.13),
-             ('001231', 21844, 22.89), ('605138', 50454, 9.91), ('603963', 37850, 13.21), ('603029', 21608, 23.14),
-             ('001222', 29833, 16.76), ('002898', 34868, 14.34), ('603106', 58754, 8.51), ('600361', 80775, 6.19),
-             ('600280', 92251, 5.42), ('002370', 100402, 4.98), ('002640', 124378, 4.02), ('002758', 37821, 13.22),
-             ('000953', 82237, 6.08), ('002747', 20602, 24.27), ('002146', 191571, 2.61), ('601696', 39620, 12.62),
-             ('000411', 31566, 15.84), ('603220', 26810, 18.65), ('000739', 26137, 19.13), ('600575', 174825, 2.86),
-             ('600257', 72464, 6.9), ('003042', 22686, 22.04), ('601059', 24522, 20.39), ('603667', 33400, 14.97)]
-
-
 def __set_target_codes(pipe_l2):
     while True:
         try:
-            datas = test_data
-            root_data = {"data": {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
-                                  "data": datas},
-                         "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
-            root_data = socket_util.encryp_client_params_sign(root_data)
-            pipe_l2.send(json.dumps(root_data))
-            print("鍚慙2鍙戦�佹暟鎹�")
-
+            _datas = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.pop()
+            if _datas:
+                timestamp = _datas[0]
+                datas = _datas[1]
+                print("鏃堕棿鎴筹細", timestamp)
+                print("鍐呭锛�", datas)
+                # 鍙鐞�20s鍐呯殑鏁版嵁
+                if time.time() - timestamp < 20 and datas:
+                    codes = [d[0] for d in datas]
+                    for code in codes:
+                        block_info.init_code(code)
+                    root_data = {"data": {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
+                                          "data": datas},
+                                 "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
+                    root_data = socket_util.encryp_client_params_sign(root_data)
+                    pipe_l2.send(json.dumps(root_data))
+                    print("璁剧疆L2浠g爜缁撴潫")
         except Exception as e:
             logging.exception(e)
         finally:
-            time.sleep(2)
-
-
-#
-# def __set_target_codes(pipe_l2):
-#     while True:
-#         try:
-#             _datas = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.pop()
-#             if _datas:
-#                 timestamp = _datas[0]
-#                 datas = _datas[1]
-#                 print("鏃堕棿鎴筹細", timestamp)
-#                 print("鍐呭锛�", datas)
-#                 # 鍙鐞�20s鍐呯殑鏁版嵁
-#                 if time.time() - timestamp < 20 and datas:
-#                     codes = [d[0] for d in datas]
-#                     for code in codes:
-#                         block_info.init_code(code)
-#                     root_data = {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
-#                                  "data": datas,
-#                                  "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
-#                     root_data = socket_util.encryp_client_params_sign(root_data)
-#                     pipe_l2.send(json.dumps(root_data))
-#                     print("璁剧疆L2浠g爜缁撴潫")
-#         except Exception as e:
-#             logging.exception(e)
-#         finally:
-#             time.sleep(1)
+            time.sleep(1)
 
 
 def __read_sync_task(pipe):

--
Gitblit v1.8.0