funcguard 0.2.0__tar.gz → 0.2.1__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.

Potentially problematic release.


This version of funcguard might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcguard
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
@@ -20,16 +20,23 @@ def time_log(message, i = 0, max_num = 0, s_time = None, start_from = 0 , return
20
20
  """
21
21
  now = datetime.now( timezone( timedelta( hours = 8 ) ) )
22
22
  time_str = "{:02d}:{:02d}:{:02d}".format( now.hour, now.minute, now.second )
23
- progress_info = ""
23
+ progress_info = eta_time_info = etr_time_info = ""
24
24
  if i < 2 or max_num < 2 :
25
- print( time_str + " " + message )
25
+ if return_field in ["end_time", "remaining_time"] :
26
+ return ""
27
+ else:
28
+ print( time_str + " " + message )
26
29
 
27
30
  else :
28
31
  # 根据start_from参数计算实际处理的项目数
29
32
  process_item = i + 1 if start_from == 0 else i
30
33
  progress_info = "{}/{}".format( process_item, max_num )
31
34
  # 检查是否应该显示预计完成时间和剩余时间
32
- if process_item % 10 == 0 and s_time is not None and process_item < max_num :
35
+ # 当return_field为"end_time"或"remaining_time"时,每次都计算时间
36
+ # 否则只在每10个处理一次时计算
37
+ should_calculate_time = (return_field in ["end_time", "remaining_time"] and process_item < max_num ) or (process_item % 10 == 0 and s_time is not None and process_item < max_num)
38
+
39
+ if should_calculate_time and s_time is not None and process_item < max_num:
33
40
  duration = now - s_time
34
41
  ev_duration = duration / process_item # 每项平均耗时
35
42
  remaining_items = max_num - process_item
@@ -37,16 +44,17 @@ def time_log(message, i = 0, max_num = 0, s_time = None, start_from = 0 , return
37
44
  end_time = now + time_left
38
45
  end_time_str = end_time.strftime( "%Y-%m-%d %H:%M" )
39
46
  remaining_time_str = str( timedelta( seconds = int( time_left.total_seconds() ) ) )
40
-
41
- # Estimated Time of Arrival(预计完成/到达时间)
42
- if return_field == "end_time" :
43
- return f"eta {end_time_str}"
44
-
45
- # Estimated Time Remaining(预计剩余时间)
46
- elif return_field == "remaining_time" :
47
- return f"etr {remaining_time_str}"
48
-
49
- progress_info = progress_info + "({})etr {}".format( end_time_str, remaining_time_str )
47
+ eta_time_info = f"eta {end_time_str}"
48
+ etr_time_info = f"etr {remaining_time_str}"
49
+ progress_info = progress_info + f" ( {eta_time_info} {etr_time_info} )"
50
+
51
+ # Estimated Time of Arrival(预计完成/到达时间)
52
+ if return_field == "end_time" :
53
+ return eta_time_info
54
+
55
+ # Estimated Time Remaining(预计剩余时间)
56
+ elif return_field == "remaining_time" :
57
+ return etr_time_info
50
58
 
51
59
  print( time_str + " " + message + " " + progress_info )
52
60
  return progress_info
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcguard
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
@@ -9,7 +9,7 @@ except FileNotFoundError:
9
9
 
10
10
  setup(
11
11
  name='funcguard',
12
- version='0.2.0',
12
+ version='0.2.1',
13
13
  packages=find_packages(),
14
14
  install_requires=[
15
15
  'requests',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes