shancx 1.9.33.163__py3-none-any.whl → 1.9.33.165__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.
shancx/NN/__init__.py CHANGED
@@ -11,11 +11,11 @@ __author_email__ = 'shancx@126.com'
11
11
  # @Time : 2023/09/27 下午8:52
12
12
  # @Author : shanchangxi
13
13
  # @File : util_log.py
14
-
15
14
  import logging
16
15
  from logging.handlers import RotatingFileHandler
17
16
  import os
18
- def _loggers(logger_name="loggers", root="./logs", phase="project", level=logging.INFO, screen=True, max_bytes=10*1024*1024, backup_count=5, overwrite=False,handlersflag=False):
17
+ from shancx import crDir
18
+ def _loggers(logger_name="loggers", root="./logs", phase="project", level=logging.INFO, screen=True, max_bytes=10*1024*1024, backup_count=5, overwrite=False,handlersflag=True):
19
19
  '''set up logger with rotating file handler'''
20
20
  l = logging.getLogger(logger_name)
21
21
  if handlersflag:
@@ -24,9 +24,7 @@ def _loggers(logger_name="loggers", root="./logs", phase="project", level=loggin
24
24
  formatter = logging.Formatter(
25
25
  "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
26
26
  log_file = os.path.join(root, '{}.log'.format(phase))
27
- log_dir = os.path.dirname(log_file)
28
- if not os.path.exists(log_dir):
29
- os.makedirs(log_dir, exist_ok=True)
27
+ crDir(log_file)
30
28
  # Use RotatingFileHandler with 'w' mode to overwrite log file if needed
31
29
  mode = 'w' if overwrite else 'a'
32
30
  fh = RotatingFileHandler(log_file, mode=mode, maxBytes=max_bytes, backupCount=backup_count)
@@ -66,30 +64,30 @@ if __name__ == "__main__":
66
64
  logger.info("这是一条INFO日志")
67
65
  '''
68
66
 
69
- import os
70
- from datetime import datetime
71
- from shancx.NN import _loggers
72
- from shancx import lock_file
73
- from shancx.wait import check_lock
74
- from shancx import crDir
75
- logger =_loggers()
76
- def check_process_data(UTC, sat_cd,basepath ="/mnt/wtx_weather_forecast/scx/test/lock_files" ):
77
- try:
78
- UTCStr = UTC.strftime("%Y%m%d%H%M")
79
- file = f"/mnt/wtx_weather_forecast/scx/test/lock_files/{sat_cd}/{UTCStr[:4]}/{UTCStr[:8]}/File_{UTCStr}.lock"
80
- crDir(file)
81
- if not lock_file(file):
82
- if check_lock(file):
83
- logger.info("data is making or maked")
84
- return True ,file
85
- return False,file
86
- except Exception as e:
87
- logger.error(f"Error in check_and_process_data: {str(e)}")
88
- return False,file
89
- """
90
- flag1,file = check_process_data(UTC, "H9SEAS" )
91
- if flag1:
92
- sys.exit()
93
- if os.path.exists(output_path): #配合使用
94
- sys.exit()
95
- """
67
+ # import os
68
+ # from datetime import datetime
69
+ # from shancx.NN import _loggers
70
+ # from shancx import lock_file
71
+ # from shancx.wait import check_lock
72
+ # from shancx import crDir
73
+ # logger =_loggers()
74
+ # def check_process_data(UTC, sat_cd,basepath ="/mnt/wtx_weather_forecast/scx/test/lock_files" ):
75
+ # try:
76
+ # UTCStr = UTC.strftime("%Y%m%d%H%M")
77
+ # file = f"/mnt/wtx_weather_forecast/scx/test/lock_files/{sat_cd}/{UTCStr[:4]}/{UTCStr[:8]}/File_{UTCStr}.lock"
78
+ # crDir(file)
79
+ # if not lock_file(file):
80
+ # if check_lock(file):
81
+ # logger.info("data is making or maked")
82
+ # return True ,file
83
+ # return False,file
84
+ # except Exception as e:
85
+ # logger.error(f"Error in check_and_process_data: {str(e)}")
86
+ # return False,file
87
+ # """
88
+ # flag1,file = check_process_data(UTC, "H9SEAS" )
89
+ # if flag1:
90
+ # sys.exit()
91
+ # if os.path.exists(output_path): #配合使用
92
+ # sys.exit()
93
+ # """
shancx/__init__.py CHANGED
@@ -346,14 +346,12 @@ from pathlib import Path
346
346
  def lock_file(lock_file_path):
347
347
  if os.path.exists(lock_file_path):
348
348
  print(f" {lock_file_path} is existded ")
349
- loggers.info(f" {lock_file_path} is existded ")
350
- return True
349
+ return False
351
350
  try:
352
351
  os.makedirs(os.path.dirname(lock_file_path), exist_ok=True)
353
352
  with open(lock_file_path, 'w') as f:
354
353
  f.write(f"process_id:{os.getpid()},create_time:{datetime.datetime.now()}")
355
- loggers.info(f"create lock file {lock_file_path}")
356
- return False
354
+ return True
357
355
  except Exception as e:
358
356
  print(f"创建锁文件失败 create lock failed : {e}")
359
357
  return False
@@ -366,7 +364,39 @@ if os.path.exists(lock_file):
366
364
  print(f"锁文件存在,已有程序在处理时次 {utc_time_str},跳过")
367
365
  return False
368
366
  """
369
-
367
+ import os
368
+ import time
369
+ def is_process_alive(pid):
370
+ try:
371
+ os.kill(pid, 0)
372
+ return True
373
+ except OSError:
374
+ return False
375
+ def check_lock(lock_file):
376
+ if not os.path.exists(lock_file):
377
+ return False
378
+ try:
379
+ with open(lock_file, 'r') as f:
380
+ content = f.read().strip()
381
+ if 'process_id:' in content and 'create_time:' in content:
382
+ pid_str = content.split('process_id:')[1].split(',')[0]
383
+ pid = int(pid_str)
384
+ if not is_process_alive(pid):
385
+ print(f"进程 {pid} 已消亡,清理锁文件")
386
+ os.remove(lock_file)
387
+ return False
388
+ else:
389
+ print(f"进程 {pid} 仍在运行,跳过执行")
390
+ return True
391
+ except Exception as e:
392
+ print(f"锁文件解析错误,清理: {e}")
393
+ os.remove(lock_file)
394
+ return False
395
+ return False
396
+ """
397
+ if check_lock(lock_file):
398
+ return False
399
+ """
370
400
  import multiprocessing
371
401
  import sys
372
402
  from typing import Optional, Literal
shancx/wait.py CHANGED
@@ -167,8 +167,7 @@ def is_process_alive(pid):
167
167
  return False
168
168
  def check_lock(lock_file):
169
169
  if not os.path.exists(lock_file):
170
- logger.info(f"{lock_file} not exists error A lock file needs to be created. ")
171
- return False
170
+ return False
172
171
  try:
173
172
  with open(lock_file, 'r') as f:
174
173
  content = f.read().strip()
@@ -176,14 +175,14 @@ def check_lock(lock_file):
176
175
  pid_str = content.split('process_id:')[1].split(',')[0]
177
176
  pid = int(pid_str)
178
177
  if not is_process_alive(pid):
179
- logger.info(f"not is_process_alive(pid)")
180
- return False
178
+ print(f"进程 {pid} 已消亡,清理锁文件")
181
179
  os.remove(lock_file)
182
180
  return False
183
181
  else:
182
+ print(f"进程 {pid} 仍在运行,跳过执行")
184
183
  return True
185
184
  except Exception as e:
186
- print(f"lock anaylysis error,clean : {e}")
185
+ print(f"锁文件解析错误,清理: {e}")
187
186
  os.remove(lock_file)
188
187
  return False
189
188
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: shancx
3
- Version: 1.9.33.163
3
+ Version: 1.9.33.165
4
4
  Summary: A simple timer decorator
5
5
  Home-page: https://gitee.com/shancx
6
6
  Author: shancx
@@ -6,7 +6,7 @@ shancx/Point.py,sha256=gyIomOVbNoz6SOcAhhTS26NHBeJ0TOwB-ljNsBWN1ZE,1909
6
6
  shancx/QC.py,sha256=gVH1jAZ2tI-sDygozwfXQgLEJNJscFuzxexWXuXHWHw,2803
7
7
  shancx/Read.py,sha256=xX4ciDoWhL9KAsN3cWvaFAOMlSVwR56AR3dSB-SBnLI,3139
8
8
  shancx/ZR.py,sha256=5APchqVoI1G2MkrN9YJSWCwfLUygcSFIsUXSo9aq1Qg,341
9
- shancx/__init__.py,sha256=jxCbCTmGO1dkdvEBgJjGqC3k8iytopcm1g2eGC3QcAs,18816
9
+ shancx/__init__.py,sha256=ejEaYlajqIeXfIpXzVeAIUfvBlExWhyu5pcc-SVFqW4,19744
10
10
  shancx/args.py,sha256=Nr80vgQpT3m31_crKGf5DvofCxyERJFbqJ1sHb1BIqs,1042
11
11
  shancx/bak.py,sha256=eKe2o1Yq7LCldoA-LXi14s_QNf1BkQsDsWJ7pDoscrw,25428
12
12
  shancx/cmp.py,sha256=cIQv-QTl-22FJa6tmHyBu_IQmMq5LnsQGGFK5jc5hMA,893
@@ -16,7 +16,7 @@ shancx/info.py,sha256=0rk_L8Z5uj9RliaZrzT-CArH9ZObmdmcp-1RxAItL08,1122
16
16
  shancx/netdfJU.py,sha256=96KR9NMLr2Kcs_OOMpX7QPujdWUj0GCEUIZ7_4_pBxw,7741
17
17
  shancx/sendM.py,sha256=CEpeHavseWILlfevhfOMYxYUIWhh4fCNkXGRsEjMxBE,3352
18
18
  shancx/tool.py,sha256=T1Uwsd5vcfKLEMGq7DmhPOmsnBNZgYq-QML8W2a6KTc,1027
19
- shancx/wait.py,sha256=Vpx-4P4Vppjo6JjaWBKKQltPtcSg-FIXbo1oe7ExqzE,8609
19
+ shancx/wait.py,sha256=OgT9JmEgMH7d3ir3TEksx0_Kyl_S4bkOKl50jvVpdFA,8575
20
20
  shancx/3D/__init__.py,sha256=pDFvW1OOEW-ueXH50NJIYdWlySHZU6sr5htzHUSeROo,1000
21
21
  shancx/Algo/Class.py,sha256=bxJ9JhIjoxl0hJfjO126YrnyHWDpxCEAZ7qcPs0Y0ic,377
22
22
  shancx/Algo/CudaPrefetcher1.py,sha256=mUVlS3txsriET26ZMZ6DYOnyzWr8Tz6wThifzWrC7k8,3951
@@ -62,7 +62,7 @@ shancx/H9/ahisearchtable.py,sha256=e2kpz-P5npgL4gzNxn8igERJuWWIysvTNLkptr5_Zcc,9
62
62
  shancx/H9/geometry.py,sha256=ZoCfgP07ANqDxyLf8uFN016DPl7QqW9pAV3sr2ekCng,95893
63
63
  shancx/Hug/__init__.py,sha256=NvcqXM0CSwXYtTr5yj4zfkag_7PZcI5tCsIHjuLNXTQ,3040
64
64
  shancx/Mos/__init__.py,sha256=IDlCLNN6a_mguYmRcAPcevHSDaud5ZhvYNSuASqztcE,1563
65
- shancx/NN/__init__.py,sha256=JQgNPBqnvckGDYnBmdQw-nauBS5mN3sba6nf1aFVJik,3204
65
+ shancx/NN/__init__.py,sha256=TpDNbhE7-q6bQal_dSbQdPOQXXRAnb8Z6-OEEJLk7CI,3182
66
66
  shancx/Plot/GlobMap.py,sha256=WRvZOf5bo8IfECk1-sN4g6K0CrcJhSoEJAiLvZAWDwg,13021
67
67
  shancx/Plot/Gray2RGB.py,sha256=yDXu1xWVi7OtrS8_ExxK_ev1988kj1ZxoNCWf-kl4Zc,2734
68
68
  shancx/Plot/__init__.py,sha256=R4pywzeVDqEWGMkWeGBAVmopgPBThiLv2RBDlGquNGc,31891
@@ -83,7 +83,7 @@ shancx/Train/multiGpu.py,sha256=D_oZeiSc7VWktpnVDwrFOC1CYZSt9rxOKY5lngE5vFg,820
83
83
  shancx/Train/prepare.py,sha256=vL_8UOA66oZCBIwCICtihsGibivtNgaVJGulJxfNdn8,6793
84
84
  shancx/Train/renet50.py,sha256=wEhYk1X96WE5zuqHqVxWLJa-A5jDNkz4z6edORNufnA,6428
85
85
  shancx/tensBoard/__init__.py,sha256=ga2C5YyJITvvQA1ocpxna_KNFnNRJVwkTjLoIglLZUQ,993
86
- shancx-1.9.33.163.dist-info/METADATA,sha256=0XB2IgkOomSLRVrhvCiupwS_OD68A3_-J1yVm4WnXHE,644
87
- shancx-1.9.33.163.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
88
- shancx-1.9.33.163.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
89
- shancx-1.9.33.163.dist-info/RECORD,,
86
+ shancx-1.9.33.165.dist-info/METADATA,sha256=Z5Sn7sjqmtn4UHqhRJFl2AmwI-n863rETpTwP6Kq_rg,644
87
+ shancx-1.9.33.165.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
88
+ shancx-1.9.33.165.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
89
+ shancx-1.9.33.165.dist-info/RECORD,,