From a42a2c023c234a11c3810d5c9d15c8e8bffffbbc Mon Sep 17 00:00:00 2001
From: "li.zhenye"
Date: Tue, 23 Aug 2022 19:41:16 +0800
Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E6=94=B9=E8=BF=87=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 18 ++++++++++++++++++
tests/test_transmit.py | 5 +++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e348716..83295b8 100644
--- a/README.md
+++ b/README.md
@@ -461,3 +461,21 @@ def __setstate__(self, state):
就是在序列化之前把不能序列化的stateful_things收起来,把`_stop_event`这个线程间同步用的东西也给收起来,然后就可以复制类内所有的变量新的独立的进程运行了,新的进程会拥有自己进程内独立的`_stop_event`,这就导致我们其实已经失去了对于这个新开辟的子进程的控制,除非它自己调用自己的self.stop。
好了,我觉得这个地方有点蠢,之后再改。
+
+不对,经过我的实验,我发先函数在调用self.stop后依然生效,这太神奇了,不过我想了一下,还是因为主进程死了所以子进程也死了并不会有什么别的原因。
+
+问题大的地方在于这里:
+
+> 2022-08-23 15:49:57,770 - root - INFO - 测试子进程文件接收器
+> 2022-08-23 15:49:58,870 - root - INFO - Spent 59.68ms to get image with shape (1024, 4096, 3)
+> 2022-08-23 15:49:59,886 - root - INFO - Spent 56.07ms to get image with shape (1024, 4096, 3)
+> 2022-08-23 15:50:00,932 - root - INFO - Spent 84.52ms to get image with shape (1024, 4096, 3)
+> 2022-08-23 15:50:01,966 - root - INFO - Spent 97.37ms to get image with shape (1024, 4096, 3)
+> 2022-08-23 15:50:02,969 - root - INFO - Spent 78.12ms to get image with shape (1024, 4096, 3)
+
+😮💨这个速度属实是拉胯,上网查了以后发现python的进程间通信(ipc)是个大问题,从2014年到2021年,关于这个队列慢的提问从来不停。
+
+
+
+
+
diff --git a/tests/test_transmit.py b/tests/test_transmit.py
index fb79e0a..c657f61 100644
--- a/tests/test_transmit.py
+++ b/tests/test_transmit.py
@@ -8,6 +8,7 @@ import transmit
from config import Config
from transmit import FileReceiver, FifoReceiver, FifoSender
from utils import ImgQueue
+from quick_queue.quick_queue import QQueue
class TransmitterTest(unittest.TestCase):
@@ -33,7 +34,8 @@ class TransmitterTest(unittest.TestCase):
def test_file_receiver_subprocess(self):
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logging.info('测试子进程文件接收器')
- image_queue = multiprocessing.Queue()
+ # image_queue = multiprocessing.Queue()
+ image_queue = QQueue()
file_receiver = FileReceiver(job_name='rgb img receive', input_dir='../data', output_queue=image_queue,
speed=1, name_pattern=None, run_process=True)
virtual_data = np.random.randint(0, 255, (1024, 4096, 3), dtype=np.uint8)
@@ -64,7 +66,6 @@ class TransmitterTest(unittest.TestCase):
input_queue.put(virtual_data)
logging.debug('put data to input queue done')
virtual_data = image_queue.get()
- # logging.info(f'Spent {(current_time - time_record) * 1000:.2f}ms to get image with shape {virtual_data.shape}')
self.assertEqual(virtual_data.shape, (1024, 4096, 3))