datacom-device-api 0.1.9__tar.gz → 0.1.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/PKG-INFO +1 -1
  2. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/pyproject.toml +1 -1
  3. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/process/terminal_process.py +42 -9
  4. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api.egg-info/PKG-INFO +1 -1
  5. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/README.md +0 -0
  6. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/setup.cfg +0 -0
  7. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/__init__.py +0 -0
  8. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/data/__init__.py +0 -0
  9. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/data/table.py +0 -0
  10. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/event/event.py +0 -0
  11. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/ext/ext_meta.py +0 -0
  12. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/ext/ext_meta_display.py +0 -0
  13. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/operation/__init__.py +0 -0
  14. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/operation/table_operation.py +0 -0
  15. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/operation/table_read_from_xlsx.py +0 -0
  16. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/operation/table_save_to_db.py +0 -0
  17. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/process/__init__.py +0 -0
  18. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/utils/__init__.py +0 -0
  19. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/utils/directory_util.py +0 -0
  20. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api/utils/logger.py +0 -0
  21. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api.egg-info/SOURCES.txt +0 -0
  22. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api.egg-info/dependency_links.txt +0 -0
  23. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api.egg-info/requires.txt +0 -0
  24. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/src/datacom_device_api.egg-info/top_level.txt +0 -0
  25. {datacom_device_api-0.1.9 → datacom_device_api-0.1.10}/test/test_table_matching.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datacom-device-api
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.14
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "datacom-device-api"
3
- version = "0.1.9"
3
+ version = "0.1.10"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -71,6 +71,7 @@ class TerminalProcess:
71
71
  self.__pool = ProcessPoolExecutor(max_workers=max_workers or os.cpu_count())
72
72
  self.__manager = Manager()
73
73
  self.__progress_queue: queue.Queue[ProgressMessage] = self.__manager.Queue()
74
+ self.__log_queue: queue.Queue[str] = self.__manager.Queue()
74
75
 
75
76
  self.__task_future_count = 0
76
77
  self.__tasks: dict[UUID, Future[Any]] = {}
@@ -135,6 +136,7 @@ class TerminalProcess:
135
136
  def _warrper_fn(
136
137
  fn: EXECUTE_FUNC_TYPE,
137
138
  progress_queue: queue.Queue[ProgressMessage],
139
+ log_queue: queue.Queue[str],
138
140
  task_id: UUID,
139
141
  *args,
140
142
  **kwargs,
@@ -143,7 +145,19 @@ class TerminalProcess:
143
145
 
144
146
  封装进度上报、完成标记和异常处理,通过队列将进度消息
145
147
  发送回主进程。任务正常结束或异常均会发送对应类型的消息。
148
+ 同时配置根 logger 使用 QueueHandler 将子进程日志转发到主进程。
146
149
  """
150
+ import logging
151
+ import logging.handlers
152
+
153
+ root_logger = logging.getLogger()
154
+ queue_handler = logging.handlers.QueueHandler(log_queue)
155
+ queue_handler.setLevel(logging.INFO)
156
+ formatter = logging.Formatter('[%(asctime)s-%(levelname)s](%(name)s): %(message)s')
157
+ queue_handler.setFormatter(formatter)
158
+ root_logger.addHandler(queue_handler)
159
+ root_logger.setLevel(logging.INFO)
160
+
147
161
  done_send = False
148
162
 
149
163
  def report(progress: float, total: float, message: str, msg_type: str = 'progress'):
@@ -183,21 +197,33 @@ class TerminalProcess:
183
197
  def run_display_progress(self) -> None:
184
198
  """进度消费线程主循环。
185
199
 
186
- 持续从队列中取出进度消息,依次更新内置进度条并触发监听器。
200
+ 持续从队列中取出进度消息和日志消息,进度消息依次更新内置进度条并触发监听器,
201
+ 日志消息通过共享 Console 输出到终端(显示在进度条上方)。
187
202
  使用带超时的轮询避免阻塞,确保停止事件触发后能及时退出。
188
203
  """
189
- while not self.__progress_thread_stop_event.is_set() or not self.__progress_queue.empty():
204
+ while not self.__progress_thread_stop_event.is_set() or not self.__progress_queue.empty() or not self.__log_queue.empty():
190
205
  try:
191
206
  message = self.__progress_queue.get(timeout=0.1)
192
207
  self.update_progress(message)
193
208
  self.trigger_progress(message.task_id, message)
194
209
  except queue.Empty:
195
- if (
196
- self.__progress_thread_stop_event.is_set()
197
- and all(futrue.done() for futrue in self.__tasks.values())
198
- ):
210
+ pass
211
+
212
+ while not self.__log_queue.empty():
213
+ try:
214
+ log_msg = self.__log_queue.get_nowait()
215
+ self.__console.print(log_msg)
216
+ except queue.Empty:
199
217
  break
200
218
 
219
+ if (
220
+ self.__progress_thread_stop_event.is_set()
221
+ and all(futrue.done() for futrue in self.__tasks.values())
222
+ and self.__progress_queue.empty()
223
+ and self.__log_queue.empty()
224
+ ):
225
+ break
226
+
201
227
  def submit(
202
228
  self,
203
229
  fn: EXECUTE_FUNC_TYPE,
@@ -217,7 +243,7 @@ class TerminalProcess:
217
243
  任务的 Future 对象,可用于获取结果或异常
218
244
  """
219
245
  task_id = uuid.uuid4()
220
- task_fn = partial(TerminalProcess._warrper_fn, fn, self.__progress_queue, task_id)
246
+ task_fn = partial(TerminalProcess._warrper_fn, fn, self.__progress_queue, self.__log_queue, task_id)
221
247
  future = self.__pool.submit(task_fn, *args, **kwargs)
222
248
  self.__tasks[task_id] = future
223
249
  self.__task_update_lisening_fn_dict[task_id] = []
@@ -240,8 +266,8 @@ class TerminalProcess:
240
266
  def shutdown(self) -> None:
241
267
  """停止任务执行并释放资源。
242
268
 
243
- 按顺序执行:等待所有任务完成 → 消费完剩余进度消息
244
- 关闭进程池 → 停止进度条。确保不会因消息未消费完而丢失进度。
269
+ 按顺序执行:等待所有任务完成 → 设置停止事件 消费线程退出并消费剩余消息 →
270
+ 关闭进程池 → 停止进度条。确保不会因消息未消费完而丢失进度或日志。
245
271
  """
246
272
  for future in self.__tasks.values():
247
273
  try:
@@ -254,6 +280,13 @@ class TerminalProcess:
254
280
  self.__progress_thread.join()
255
281
  self.__progress_thread = None
256
282
 
283
+ while not self.__log_queue.empty():
284
+ try:
285
+ log_msg = self.__log_queue.get_nowait()
286
+ self.__console.print(log_msg)
287
+ except queue.Empty:
288
+ break
289
+
257
290
  self.__pool.shutdown(wait=True)
258
291
  self.__progress.stop()
259
292
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datacom-device-api
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.14
6
6
  Description-Content-Type: text/markdown