xtn-tools-pro 1.0.0.5.0__py3-none-any.whl → 1.0.0.5.2__py3-none-any.whl

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.
@@ -16,6 +16,7 @@ import threading
16
16
  import multiprocessing
17
17
  import concurrent.futures
18
18
  from multiprocessing import Process
19
+ from xtn_tools_pro.utils.time_utils import get_time_now_timestamp
19
20
 
20
21
 
21
22
  class GoFun:
@@ -78,39 +79,66 @@ class GoFun:
78
79
  upload_queue = multiprocessing.Queue()
79
80
  proxies_dict = manager.dict()
80
81
 
81
- processes_list = []
82
82
  processes_item_info = {
83
83
  "_download_and_upload_task": {
84
84
  "target": self._download_and_upload_task,
85
85
  "name": "_download_and_upload_task",
86
86
  "args": (download_queue, upload_queue, proxies_dict, self.__ini_info, logger),
87
+ "start_time": 0,
88
+ "restart_time": int(restart_time),
87
89
  },
88
90
  "_go_task_fun_task": {
89
91
  "target": self._go_task_fun_task,
90
92
  "name": "_go_task_fun_task",
91
93
  "args": (download_queue, upload_queue, proxies_dict, self.__ini_info, go_task_function, logger),
94
+ "start_time": 0,
95
+ "restart_time": int(restart_time),
92
96
  },
93
97
  }
94
98
 
95
99
  for p_item in processes_item_info.values():
96
100
  task_process = multiprocessing.Process(target=p_item["target"], name=p_item["name"], args=p_item["args"])
97
- processes_list.append(task_process)
101
+ processes_item_info[p_item["name"]]["task_process"] = task_process
102
+ processes_item_info[p_item["name"]]["start_time"] = get_time_now_timestamp(is_time_10=True)
98
103
  task_process.start()
99
104
  logger.warning(f"进程已启动,{task_process.is_alive()},{task_process.name},{task_process.pid}")
100
105
 
101
106
  while True:
102
107
  time.sleep(10)
103
- for p in processes_list:
108
+ for p_item_info in processes_item_info.values():
109
+ task_process = p_item_info["task_process"]
110
+ task_process_start_time = p_item_info["start_time"]
111
+ task_process_restart_time = p_item_info.get("restart_time", 0)
104
112
  # 检查子进程是否存活
105
- if not p.is_alive():
106
- logger.critical(f"进程不存在,{p.is_alive()},{p.name},{p.pid}")
107
- processes_list.remove(p)
108
- p_item = processes_item_info[p.name]
113
+ task_process_pid = task_process.pid
114
+ task_process_name = task_process.name
115
+ task_process_is_alive = task_process.is_alive()
116
+ if not task_process_is_alive:
117
+ logger.critical(f"进程不存在,{task_process_is_alive},{task_process_name},{task_process_pid}")
118
+ p_item = processes_item_info[task_process_name]
109
119
  task_process = multiprocessing.Process(target=p_item["target"], name=p_item["name"],
110
120
  args=p_item["args"])
111
- processes_list.append(task_process)
121
+
122
+ processes_item_info[task_process_name]["task_process"] = task_process
123
+ processes_item_info[task_process_name]["start_time"] = get_time_now_timestamp(is_time_10=True)
112
124
  task_process.start()
113
125
  logger.warning(f"进程已重启,{task_process.is_alive()},{task_process.name},{task_process.pid}")
126
+ else:
127
+ if not task_process_restart_time:
128
+ continue
129
+ if task_process_start_time + task_process_restart_time <= get_time_now_timestamp(is_time_10=True):
130
+ logger.critical(
131
+ f"进程已超过设置时间,正在强制关闭进程,{task_process_restart_time},{task_process_is_alive},{task_process_name},{task_process_pid}")
132
+ task_process.terminate()
133
+ task_process.join() # 等待进程确实结束
134
+ p_item = processes_item_info[task_process_name]
135
+ task_process = multiprocessing.Process(target=p_item["target"], name=p_item["name"],
136
+ args=p_item["args"])
137
+
138
+ processes_item_info[task_process_name]["task_process"] = task_process
139
+ processes_item_info[task_process_name]["start_time"] = get_time_now_timestamp(is_time_10=True)
140
+ task_process.start()
141
+ logger.warning(f"进程已重启,{task_process.is_alive()},{task_process.name},{task_process.pid}")
114
142
 
115
143
  def __get_external_ip(self, logger):
116
144
  """
@@ -360,3 +388,17 @@ class GoFun:
360
388
  "upload_task_tine": "回写间隔",
361
389
  }
362
390
  return ini_dict
391
+
392
+ def get_download_task(self, download_queue, block, timeout):
393
+ """
394
+ 获取下载任务
395
+ :param download_queue:下载队列
396
+ :param block: 是否阻塞等待 True阻塞/False不阻塞
397
+ :param timeout:
398
+ :return:
399
+ """
400
+ try:
401
+ task_item = download_queue.get(block=block, timeout=timeout)
402
+ return task_item
403
+ except Exception as e:
404
+ self.logger.critical(f"get_download_task 获取下载任务 报错 {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xtn-tools-pro
3
- Version: 1.0.0.5.0
3
+ Version: 1.0.0.5.2
4
4
  Summary: xtn 开发工具
5
5
  Author: xtn
6
6
  Author-email: czw011122@gmail.com
@@ -10,7 +10,7 @@ xtn_tools_pro/proxy/XiaoXiangProxy.py,sha256=45SsMZDc-3Ta4THX38vScjaeRBJSp420AJw
10
10
  xtn_tools_pro/proxy/__init__.py,sha256=WRwh6s2lruMu5buh0ejo9EK54kWT_VQhCsFGNFAmcyo,418
11
11
  xtn_tools_pro/proxy/proxy.py,sha256=No6E1pFY5yx2F4976pXPrLtq-QEVp79KupzcufjSN58,8703
12
12
  xtn_tools_pro/task_pro/__init__.py,sha256=nK3U47hWwE1H875ieEToH9r-jzXHS-PXk8cDstOvRE8,418
13
- xtn_tools_pro/task_pro/go_fun.py,sha256=AQ8Hc0gifSzjRPZrWqB0x1NVG4t4B-8oexXzDuo-Tf4,15448
13
+ xtn_tools_pro/task_pro/go_fun.py,sha256=bUalIre1D1DZKAz87sYVYD4YY7zKsl_UNcv7Ro5hg9A,18106
14
14
  xtn_tools_pro/utils/__init__.py,sha256=I1_n_NP23F2lBqlF4EOlnOdLYxM8M4pbn63UhJN1hRE,418
15
15
  xtn_tools_pro/utils/crypto.py,sha256=RZ5AET4udlraACWMeNF-17JiZ2R6Ahb47_j4tjkV7LE,3190
16
16
  xtn_tools_pro/utils/file_utils.py,sha256=VfdIxog4s1UW5NpKkCvQsUs9qHjLoNCnstZbnftkT4w,2046
@@ -19,8 +19,8 @@ xtn_tools_pro/utils/log.py,sha256=m0WtTWkkwtrki1ftP8vCDR8bMfK2gcfUGx5J2x2IlLQ,10
19
19
  xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,1657
20
20
  xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
21
21
  xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
22
- xtn_tools_pro-1.0.0.5.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- xtn_tools_pro-1.0.0.5.0.dist-info/METADATA,sha256=CakMpRsw3h5eJG3xRck90T3iMKM_BTwmP7wi_VgiVFo,455
24
- xtn_tools_pro-1.0.0.5.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
25
- xtn_tools_pro-1.0.0.5.0.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
26
- xtn_tools_pro-1.0.0.5.0.dist-info/RECORD,,
22
+ xtn_tools_pro-1.0.0.5.2.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ xtn_tools_pro-1.0.0.5.2.dist-info/METADATA,sha256=_tqvdchxRkhjxzCQY-kW-yEZMold07wZma49sksTyNY,455
24
+ xtn_tools_pro-1.0.0.5.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
25
+ xtn_tools_pro-1.0.0.5.2.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
26
+ xtn_tools_pro-1.0.0.5.2.dist-info/RECORD,,