ul-api-utils 7.11.6__py3-none-any.whl → 7.11.8__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.

Potentially problematic release.


This version of ul-api-utils might be problematic. Click here for more details.

@@ -1,4 +1,5 @@
1
1
  import argparse
2
+ import gc
2
3
  import os
3
4
  import re
4
5
  import subprocess
@@ -27,6 +28,7 @@ class CmdStart(Cmd):
27
28
  max_requests: int
28
29
  max_requests_jitter: int
29
30
  worker_class: str
31
+ freeze_gc: bool
30
32
  statsd_endpoint: Optional[str]
31
33
  statsd_prefix: Optional[str]
32
34
 
@@ -56,8 +58,12 @@ class CmdStart(Cmd):
56
58
  parser.add_argument('--worker-class', dest='worker_class', type=str, default='sync', required=False)
57
59
  parser.add_argument('--statsd_endpoint', dest='statsd_endpoint', type=str, default=None, required=False)
58
60
  parser.add_argument('--statsd_prefix', dest='statsd_prefix', type=str, default=None, required=False)
61
+ parser.add_argument('--freeze-gc', dest='freeze_gc', type=bool, default=False, required=False)
59
62
 
60
63
  def run(self) -> None:
64
+ if self.freeze_gc:
65
+ gc.disable()
66
+
61
67
  env = os.environ.copy()
62
68
  name = re.sub(r'[^0-9a-z]+', '-', f'gncrn-{os.path.relpath(self.app_dir, os.getcwd()).lower().strip("/").strip()}')
63
69
  env['PYTHONUNBUFFERED'] = os.environ.get('PYTHONUNBUFFERED', '0')
@@ -70,15 +76,17 @@ class CmdStart(Cmd):
70
76
 
71
77
  assert len(APPLICATION_GUNICORN_WORKERS) > 0
72
78
 
73
- conf = os.path.abspath(os.path.normpath(os.path.join(THIS_LIB_CWD, "commands", "start", "gunicorn.conf.py")))
74
79
  debug = (self.debug and self.env == ENV_LOCAL)
80
+ local_conf = os.path.abspath(os.path.normpath(os.path.join(THIS_LIB_CWD, "commands", "start", "gunicorn.conf.local.py")))
81
+ prod_conf = os.path.abspath(os.path.normpath(os.path.join(THIS_LIB_CWD, "commands", "start", "gunicorn.conf.py")))
82
+ gunicorn_config = prod_conf if self.freeze_gc and not debug else local_conf
75
83
 
76
84
  args = [
77
85
  f'-n={name}',
78
86
  f'-w={APPLICATION_GUNICORN_WORKERS}',
79
87
  f'--worker-class={self.worker_class}',
80
88
  f'-b=0.0.0.0:{self.port}',
81
- f'--config={conf}',
89
+ f'--config={gunicorn_config}',
82
90
  '--log-level=INFO',
83
91
  f'--max-requests={self.max_requests}',
84
92
  f'--max-requests-jitter={self.max_requests_jitter}',
File without changes
@@ -0,0 +1,26 @@
1
+ import gc
2
+ from typing import Any
3
+
4
+ from ul_py_tool.utils.write_stdout import write_stdout
5
+
6
+
7
+ def when_ready(server: Any) -> None:
8
+ """
9
+ Use only with --preload option.
10
+ Called just after the server is started.
11
+ Freeze garbage collector objects after preloading the application.
12
+ https://docs.gunicorn.org/en/20.1.0/settings.html?highlight=preload#when-ready
13
+ """
14
+ gc.freeze()
15
+ write_stdout("Objects frozen in permanent generation: ", gc.get_freeze_count())
16
+
17
+
18
+ def post_fork(server: Any, worker: Any) -> None:
19
+ """
20
+ Works only with --preload.
21
+ Called just after a worker has been forked.
22
+ Enable garbage collection on each worker if it's not enabled for some reason.
23
+ https://docs.gunicorn.org/en/20.1.0/settings.html?highlight=preload#post-fork
24
+ """
25
+ write_stdout("Enabling GC for worker", worker.pid)
26
+ gc.enable()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 7.11.6
3
+ Version: 7.11.8
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -50,6 +50,7 @@ Requires-Dist: werkzeug (==2.3.7)
50
50
  Requires-Dist: frozendict (==2.4.4)
51
51
  Requires-Dist: wtforms (==3.0.1)
52
52
  Requires-Dist: wtforms-alchemy (==0.18.0)
53
+ Requires-Dist: pathvalidate (==3.2.0)
53
54
 
54
55
  # Generic library api-utils
55
56
 
@@ -41,10 +41,11 @@ ul_api_utils/commands/cmd_enc_keys.py,sha256=-Tblh6lI7G6M5YVwbVQqZmXhBMiIpB3a7b0
41
41
  ul_api_utils/commands/cmd_gen_api_user_token.py,sha256=Vg7oEYHvof7DSLat9yJ_k5AYL9ZOC4Jvd38DBn5U-R0,2730
42
42
  ul_api_utils/commands/cmd_gen_new_api_user.py,sha256=ICZbKqz2D6DRvjwtNM08rNjIlWN3qClcUQw5L8FxRBY,4549
43
43
  ul_api_utils/commands/cmd_generate_api_docs.py,sha256=pafX88RjcSMFruSk6qy8Xfao3MXo1yolI4rkC_bmMSQ,9612
44
- ul_api_utils/commands/cmd_start.py,sha256=DeFcgy2GlL_97HP33mFS2k0chHAyun8EkVuFYrgJIhg,4301
44
+ ul_api_utils/commands/cmd_start.py,sha256=cd1PLHaB4LXNHwZBP1NyllHHSetuI-XUDZw2MGlbkWE,4717
45
45
  ul_api_utils/commands/cmd_worker_start.py,sha256=1tt4_mL8T8_q7i1bqnfjPSkSYlRNNNp8eJ-5rTYj36w,2593
46
46
  ul_api_utils/commands/start/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
- ul_api_utils/commands/start/gunicorn.conf.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
+ ul_api_utils/commands/start/gunicorn.conf.local.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
+ ul_api_utils/commands/start/gunicorn.conf.py,sha256=_PPfbYvKLLrL8jelqBGjobtS3vYydooANVq0fc0hZUs,860
48
49
  ul_api_utils/commands/start/wsgi.py,sha256=ZBFx66XP8iNliK3vkB6yWRkCq2-ItgieweBmWaXtDa4,681
49
50
  ul_api_utils/conf/ul-debugger-main.js,sha256=XgzaH1AWAG4_PW9mRaoJGJOKeEA5T61j7yIouZjU65s,999747
50
51
  ul_api_utils/conf/ul-debugger-ui.js,sha256=bNwv6ntu8RjCrH33H5eTUtFXdBoMrgFt3P87ujbBmRU,2043
@@ -147,9 +148,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
147
148
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
148
149
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
149
150
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=QLZ7DFta01Z7DOK9Z5Iq4uf_CmvDkVReis-GAl_QN48,1447
150
- ul_api_utils-7.11.6.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
151
- ul_api_utils-7.11.6.dist-info/METADATA,sha256=7MnAp-yMLgMQxy2W8StpSEBp_mddH-C-It3NRT5ots8,14787
152
- ul_api_utils-7.11.6.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
153
- ul_api_utils-7.11.6.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
154
- ul_api_utils-7.11.6.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
155
- ul_api_utils-7.11.6.dist-info/RECORD,,
151
+ ul_api_utils-7.11.8.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
152
+ ul_api_utils-7.11.8.dist-info/METADATA,sha256=lnHLRvYPEe9Xt6oT73gt4cbZ4KAeGPSISCht-cJT5n0,14825
153
+ ul_api_utils-7.11.8.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
154
+ ul_api_utils-7.11.8.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
155
+ ul_api_utils-7.11.8.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
156
+ ul_api_utils-7.11.8.dist-info/RECORD,,