leasepool 0.1.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.
Files changed (183) hide show
  1. leasepool-0.1.1/.gitignore +12 -0
  2. leasepool-0.1.1/.readthedocs.yaml +22 -0
  3. leasepool-0.1.1/LICENSE +202 -0
  4. leasepool-0.1.1/PKG-INFO +345 -0
  5. leasepool-0.1.1/README.md +317 -0
  6. leasepool-0.1.1/docs/Makefile +20 -0
  7. leasepool-0.1.1/docs/_build/html/.buildinfo +4 -0
  8. leasepool-0.1.1/docs/_build/html/.doctrees/__intersphinx_cache__/python_objects.inv +0 -0
  9. leasepool-0.1.1/docs/_build/html/.doctrees/api/backends.doctree +0 -0
  10. leasepool-0.1.1/docs/_build/html/.doctrees/api/exceptions.doctree +0 -0
  11. leasepool-0.1.1/docs/_build/html/.doctrees/api/grinder.doctree +0 -0
  12. leasepool-0.1.1/docs/_build/html/.doctrees/api/index.doctree +0 -0
  13. leasepool-0.1.1/docs/_build/html/.doctrees/api/lease.doctree +0 -0
  14. leasepool-0.1.1/docs/_build/html/.doctrees/api/manager.doctree +0 -0
  15. leasepool-0.1.1/docs/_build/html/.doctrees/api/process-logging.doctree +0 -0
  16. leasepool-0.1.1/docs/_build/html/.doctrees/changelog.doctree +0 -0
  17. leasepool-0.1.1/docs/_build/html/.doctrees/concepts.doctree +0 -0
  18. leasepool-0.1.1/docs/_build/html/.doctrees/configuration.doctree +0 -0
  19. leasepool-0.1.1/docs/_build/html/.doctrees/contributing.doctree +0 -0
  20. leasepool-0.1.1/docs/_build/html/.doctrees/environment.pickle +0 -0
  21. leasepool-0.1.1/docs/_build/html/.doctrees/examples.doctree +0 -0
  22. leasepool-0.1.1/docs/_build/html/.doctrees/faq.doctree +0 -0
  23. leasepool-0.1.1/docs/_build/html/.doctrees/guides/adaptive-sizing.doctree +0 -0
  24. leasepool-0.1.1/docs/_build/html/.doctrees/guides/error-handling.doctree +0 -0
  25. leasepool-0.1.1/docs/_build/html/.doctrees/guides/process-backend.doctree +0 -0
  26. leasepool-0.1.1/docs/_build/html/.doctrees/guides/process-logging.doctree +0 -0
  27. leasepool-0.1.1/docs/_build/html/.doctrees/guides/thread-backend.doctree +0 -0
  28. leasepool-0.1.1/docs/_build/html/.doctrees/guides/work-grinder.doctree +0 -0
  29. leasepool-0.1.1/docs/_build/html/.doctrees/index.doctree +0 -0
  30. leasepool-0.1.1/docs/_build/html/.doctrees/installation.doctree +0 -0
  31. leasepool-0.1.1/docs/_build/html/.doctrees/patterns/fastapi.doctree +0 -0
  32. leasepool-0.1.1/docs/_build/html/.doctrees/patterns/redis-asyncio.doctree +0 -0
  33. leasepool-0.1.1/docs/_build/html/.doctrees/quickstart.doctree +0 -0
  34. leasepool-0.1.1/docs/_build/html/.doctrees/readthedocs.doctree +0 -0
  35. leasepool-0.1.1/docs/_build/html/_modules/index.html +303 -0
  36. leasepool-0.1.1/docs/_build/html/_modules/leasepool/_process_logging.html +464 -0
  37. leasepool-0.1.1/docs/_build/html/_modules/leasepool/backends.html +409 -0
  38. leasepool-0.1.1/docs/_build/html/_modules/leasepool/exceptions.html +332 -0
  39. leasepool-0.1.1/docs/_build/html/_modules/leasepool/grinder.html +808 -0
  40. leasepool-0.1.1/docs/_build/html/_modules/leasepool/manager.html +1172 -0
  41. leasepool-0.1.1/docs/_build/html/_sources/api/backends.rst.txt +15 -0
  42. leasepool-0.1.1/docs/_build/html/_sources/api/exceptions.rst.txt +7 -0
  43. leasepool-0.1.1/docs/_build/html/_sources/api/grinder.rst.txt +53 -0
  44. leasepool-0.1.1/docs/_build/html/_sources/api/index.rst.txt +12 -0
  45. leasepool-0.1.1/docs/_build/html/_sources/api/lease.rst.txt +49 -0
  46. leasepool-0.1.1/docs/_build/html/_sources/api/manager.rst.txt +84 -0
  47. leasepool-0.1.1/docs/_build/html/_sources/api/process-logging.rst.txt +19 -0
  48. leasepool-0.1.1/docs/_build/html/_sources/changelog.rst.txt +22 -0
  49. leasepool-0.1.1/docs/_build/html/_sources/concepts.rst.txt +134 -0
  50. leasepool-0.1.1/docs/_build/html/_sources/configuration.rst.txt +198 -0
  51. leasepool-0.1.1/docs/_build/html/_sources/contributing.rst.txt +43 -0
  52. leasepool-0.1.1/docs/_build/html/_sources/examples.rst.txt +69 -0
  53. leasepool-0.1.1/docs/_build/html/_sources/faq.rst.txt +59 -0
  54. leasepool-0.1.1/docs/_build/html/_sources/guides/adaptive-sizing.rst.txt +52 -0
  55. leasepool-0.1.1/docs/_build/html/_sources/guides/error-handling.rst.txt +75 -0
  56. leasepool-0.1.1/docs/_build/html/_sources/guides/process-backend.rst.txt +94 -0
  57. leasepool-0.1.1/docs/_build/html/_sources/guides/process-logging.rst.txt +90 -0
  58. leasepool-0.1.1/docs/_build/html/_sources/guides/thread-backend.rst.txt +34 -0
  59. leasepool-0.1.1/docs/_build/html/_sources/guides/work-grinder.rst.txt +82 -0
  60. leasepool-0.1.1/docs/_build/html/_sources/index.rst.txt +53 -0
  61. leasepool-0.1.1/docs/_build/html/_sources/installation.rst.txt +55 -0
  62. leasepool-0.1.1/docs/_build/html/_sources/patterns/fastapi.rst.txt +48 -0
  63. leasepool-0.1.1/docs/_build/html/_sources/patterns/redis-asyncio.rst.txt +54 -0
  64. leasepool-0.1.1/docs/_build/html/_sources/quickstart.rst.txt +76 -0
  65. leasepool-0.1.1/docs/_build/html/_sources/readthedocs.rst.txt +53 -0
  66. leasepool-0.1.1/docs/_build/html/_static/base-stemmer.js +476 -0
  67. leasepool-0.1.1/docs/_build/html/_static/basic.css +906 -0
  68. leasepool-0.1.1/docs/_build/html/_static/check-solid.svg +4 -0
  69. leasepool-0.1.1/docs/_build/html/_static/clipboard.min.js +7 -0
  70. leasepool-0.1.1/docs/_build/html/_static/copy-button.svg +5 -0
  71. leasepool-0.1.1/docs/_build/html/_static/copybutton.css +94 -0
  72. leasepool-0.1.1/docs/_build/html/_static/copybutton.js +248 -0
  73. leasepool-0.1.1/docs/_build/html/_static/copybutton_funcs.js +73 -0
  74. leasepool-0.1.1/docs/_build/html/_static/debug.css +69 -0
  75. leasepool-0.1.1/docs/_build/html/_static/doctools.js +150 -0
  76. leasepool-0.1.1/docs/_build/html/_static/documentation_options.js +13 -0
  77. leasepool-0.1.1/docs/_build/html/_static/english-stemmer.js +1066 -0
  78. leasepool-0.1.1/docs/_build/html/_static/file.png +0 -0
  79. leasepool-0.1.1/docs/_build/html/_static/language_data.js +13 -0
  80. leasepool-0.1.1/docs/_build/html/_static/minus.png +0 -0
  81. leasepool-0.1.1/docs/_build/html/_static/plus.png +0 -0
  82. leasepool-0.1.1/docs/_build/html/_static/pygments.css +250 -0
  83. leasepool-0.1.1/docs/_build/html/_static/scripts/furo-extensions.js +0 -0
  84. leasepool-0.1.1/docs/_build/html/_static/scripts/furo.js +3 -0
  85. leasepool-0.1.1/docs/_build/html/_static/scripts/furo.js.LICENSE.txt +7 -0
  86. leasepool-0.1.1/docs/_build/html/_static/scripts/furo.js.map +1 -0
  87. leasepool-0.1.1/docs/_build/html/_static/searchtools.js +693 -0
  88. leasepool-0.1.1/docs/_build/html/_static/skeleton.css +296 -0
  89. leasepool-0.1.1/docs/_build/html/_static/sphinx_highlight.js +159 -0
  90. leasepool-0.1.1/docs/_build/html/_static/styles/furo-extensions.css +2 -0
  91. leasepool-0.1.1/docs/_build/html/_static/styles/furo-extensions.css.map +1 -0
  92. leasepool-0.1.1/docs/_build/html/_static/styles/furo.css +2 -0
  93. leasepool-0.1.1/docs/_build/html/_static/styles/furo.css.map +1 -0
  94. leasepool-0.1.1/docs/_build/html/api/backends.html +484 -0
  95. leasepool-0.1.1/docs/_build/html/api/exceptions.html +384 -0
  96. leasepool-0.1.1/docs/_build/html/api/grinder.html +619 -0
  97. leasepool-0.1.1/docs/_build/html/api/index.html +364 -0
  98. leasepool-0.1.1/docs/_build/html/api/lease.html +443 -0
  99. leasepool-0.1.1/docs/_build/html/api/manager.html +600 -0
  100. leasepool-0.1.1/docs/_build/html/api/process-logging.html +628 -0
  101. leasepool-0.1.1/docs/_build/html/changelog.html +356 -0
  102. leasepool-0.1.1/docs/_build/html/concepts.html +459 -0
  103. leasepool-0.1.1/docs/_build/html/configuration.html +514 -0
  104. leasepool-0.1.1/docs/_build/html/contributing.html +385 -0
  105. leasepool-0.1.1/docs/_build/html/examples.html +603 -0
  106. leasepool-0.1.1/docs/_build/html/faq.html +400 -0
  107. leasepool-0.1.1/docs/_build/html/genindex.html +609 -0
  108. leasepool-0.1.1/docs/_build/html/guides/adaptive-sizing.html +455 -0
  109. leasepool-0.1.1/docs/_build/html/guides/error-handling.html +539 -0
  110. leasepool-0.1.1/docs/_build/html/guides/process-backend.html +487 -0
  111. leasepool-0.1.1/docs/_build/html/guides/process-logging.html +496 -0
  112. leasepool-0.1.1/docs/_build/html/guides/thread-backend.html +491 -0
  113. leasepool-0.1.1/docs/_build/html/guides/work-grinder.html +605 -0
  114. leasepool-0.1.1/docs/_build/html/index.html +462 -0
  115. leasepool-0.1.1/docs/_build/html/installation.html +393 -0
  116. leasepool-0.1.1/docs/_build/html/objects.inv +0 -0
  117. leasepool-0.1.1/docs/_build/html/patterns/fastapi.html +370 -0
  118. leasepool-0.1.1/docs/_build/html/patterns/redis-asyncio.html +393 -0
  119. leasepool-0.1.1/docs/_build/html/py-modindex.html +334 -0
  120. leasepool-0.1.1/docs/_build/html/quickstart.html +578 -0
  121. leasepool-0.1.1/docs/_build/html/readthedocs.html +394 -0
  122. leasepool-0.1.1/docs/_build/html/search.html +312 -0
  123. leasepool-0.1.1/docs/_build/html/searchindex.js +1 -0
  124. leasepool-0.1.1/docs/make.bat +31 -0
  125. leasepool-0.1.1/docs/requirements.txt +4 -0
  126. leasepool-0.1.1/docs/source/api/backends.rst +15 -0
  127. leasepool-0.1.1/docs/source/api/exceptions.rst +7 -0
  128. leasepool-0.1.1/docs/source/api/grinder.rst +53 -0
  129. leasepool-0.1.1/docs/source/api/index.rst +12 -0
  130. leasepool-0.1.1/docs/source/api/lease.rst +49 -0
  131. leasepool-0.1.1/docs/source/api/manager.rst +84 -0
  132. leasepool-0.1.1/docs/source/api/process-logging.rst +19 -0
  133. leasepool-0.1.1/docs/source/changelog.rst +22 -0
  134. leasepool-0.1.1/docs/source/concepts.rst +134 -0
  135. leasepool-0.1.1/docs/source/conf.py +65 -0
  136. leasepool-0.1.1/docs/source/configuration.rst +198 -0
  137. leasepool-0.1.1/docs/source/contributing.rst +43 -0
  138. leasepool-0.1.1/docs/source/examples.rst +69 -0
  139. leasepool-0.1.1/docs/source/faq.rst +59 -0
  140. leasepool-0.1.1/docs/source/guides/adaptive-sizing.rst +52 -0
  141. leasepool-0.1.1/docs/source/guides/error-handling.rst +75 -0
  142. leasepool-0.1.1/docs/source/guides/process-backend.rst +94 -0
  143. leasepool-0.1.1/docs/source/guides/process-logging.rst +90 -0
  144. leasepool-0.1.1/docs/source/guides/thread-backend.rst +34 -0
  145. leasepool-0.1.1/docs/source/guides/work-grinder.rst +82 -0
  146. leasepool-0.1.1/docs/source/index.rst +76 -0
  147. leasepool-0.1.1/docs/source/installation.rst +55 -0
  148. leasepool-0.1.1/docs/source/patterns/fastapi.rst +48 -0
  149. leasepool-0.1.1/docs/source/quickstart.rst +76 -0
  150. leasepool-0.1.1/docs/source/readthedocs.rst +53 -0
  151. leasepool-0.1.1/examples/00_quickstart_thread_backend.py +47 -0
  152. leasepool-0.1.1/examples/01_lease_context_manager.py +63 -0
  153. leasepool-0.1.1/examples/02_manual_acquire_release.py +63 -0
  154. leasepool-0.1.1/examples/03_wait_timeout_unavailable.py +68 -0
  155. leasepool-0.1.1/examples/04_adaptive_sizing.py +66 -0
  156. leasepool-0.1.1/examples/05_stats_and_counts.py +54 -0
  157. leasepool-0.1.1/examples/06_lease_expiry_and_revocation.py +61 -0
  158. leasepool-0.1.1/examples/07_process_backend_cpu_work.py +58 -0
  159. leasepool-0.1.1/examples/08_work_grinder_submit.py +57 -0
  160. leasepool-0.1.1/examples/09_work_grinder_enqueue.py +59 -0
  161. leasepool-0.1.1/examples/10_submit_from_thread.py +68 -0
  162. leasepool-0.1.1/examples/11_error_handling.py +63 -0
  163. leasepool-0.1.1/examples/12_interpreter_backend_future_python314.py +54 -0
  164. leasepool-0.1.1/examples/13_process_log_forwarding.py +71 -0
  165. leasepool-0.1.1/examples/14_complete_library_walkthrough.py +98 -0
  166. leasepool-0.1.1/examples/README_EXAMPLES.md +88 -0
  167. leasepool-0.1.1/examples/fastapi_lifespan_pattern.py +68 -0
  168. leasepool-0.1.1/pyproject.toml +60 -0
  169. leasepool-0.1.1/src/leasepool/__init__.py +28 -0
  170. leasepool-0.1.1/src/leasepool/_process_logging.py +141 -0
  171. leasepool-0.1.1/src/leasepool/backends.py +98 -0
  172. leasepool-0.1.1/src/leasepool/exceptions.py +18 -0
  173. leasepool-0.1.1/src/leasepool/grinder.py +479 -0
  174. leasepool-0.1.1/src/leasepool/manager.py +840 -0
  175. leasepool-0.1.1/src/leasepool/py.typed +0 -0
  176. leasepool-0.1.1/src/leasepool/types.py +7 -0
  177. leasepool-0.1.1/tests/README_TESTING.md +27 -0
  178. leasepool-0.1.1/tests/helpers.py +80 -0
  179. leasepool-0.1.1/tests/test_backends.py +79 -0
  180. leasepool-0.1.1/tests/test_grinder_lifecycle.py +286 -0
  181. leasepool-0.1.1/tests/test_manager_lifecycle.py +404 -0
  182. leasepool-0.1.1/tests/test_manager_validation.py +134 -0
  183. leasepool-0.1.1/tests/test_process_backend.py +179 -0
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ .vscode/
3
+ __pycache__/
4
+ *.py[cod]
5
+ .pytest_cache/
6
+ .mypy_cache/
7
+ .ruff_cache/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ .coverage
12
+ htmlcov/
@@ -0,0 +1,22 @@
1
+ # Read the Docs configuration file for leasepool.
2
+ # Place this file in your project root.
3
+ #
4
+ # Reference:
5
+ # https://docs.readthedocs.com/platform/stable/config-file/v2.html
6
+
7
+ version: 2
8
+
9
+ build:
10
+ os: ubuntu-24.04
11
+ tools:
12
+ python: "3.11"
13
+
14
+ sphinx:
15
+ configuration: docs/source/conf.py
16
+ builder: html
17
+
18
+ python:
19
+ install:
20
+ - requirements: docs/requirements.txt
21
+ - method: pip
22
+ path: .
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,345 @@
1
+ Metadata-Version: 2.4
2
+ Name: leasepool
3
+ Version: 0.1.1
4
+ Summary: Executor leasing, backpressure, and adaptive CPU/I/O offloading for async Python.
5
+ Project-URL: Homepage, https://github.com/jackofsometrades99/leasepool
6
+ Project-URL: Repository, https://pypi.org/project/leasepool/
7
+ Project-URL: Documentation, https://leasepool.readthedocs.io/en/latest/
8
+ Author: Sambhu Nampoothiri G
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: asyncio,backpressure,concurrent.futures,executor,processpool,threadpool
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Provides-Extra: dev
23
+ Requires-Dist: mypy>=1.8; extra == 'dev'
24
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
25
+ Requires-Dist: pytest>=8.0; extra == 'dev'
26
+ Requires-Dist: ruff>=0.5; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # leasepool
30
+
31
+ **Executor leasing, backpressure, and adaptive CPU/I/O offloading for async Python.**
32
+
33
+ `leasepool` helps async applications borrow local executor capacity safely. Instead
34
+ of passing raw `ThreadPoolExecutor` or `ProcessPoolExecutor` objects around your
35
+ codebase, callers acquire short-lived leases, run synchronous work, and return the
36
+ executor to the manager.
37
+
38
+ Use it when you need to run blocking I/O, legacy sync SDK calls, or CPU-heavy
39
+ functions from an `asyncio` application without letting unbounded executor usage
40
+ spread through the service.
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install leasepool
46
+ ```
47
+
48
+ For local development from this repository:
49
+
50
+ ```bash
51
+ pip install -e .
52
+ ```
53
+
54
+ ## Project links
55
+
56
+ - GitHub: https://github.com/jackofsometrades99/leasepool
57
+ - PyPI: https://pypi.org/project/leasepool/
58
+ - Official Documentation: https://leasepool.readthedocs.io/en/latest/
59
+
60
+ ## Free-threaded Python / no-GIL support
61
+
62
+ `leasepool` is a pure Python package and does not ship native extension modules.
63
+ It is intended to work on CPython free-threaded builds.
64
+
65
+ Current support level:
66
+
67
+ - CPython free-threaded builds: Stable
68
+ - Package classifier: `Programming Language :: Python :: Free Threading :: 3 - Stable`
69
+
70
+ Note that `leasepool` can manage executor leases safely, but functions submitted by
71
+ users are still responsible for their own thread-safety when run concurrently.
72
+
73
+ ## Quickstart
74
+
75
+ ```python
76
+ import asyncio
77
+ import time
78
+
79
+ from leasepool import ExecutorBackend, LeasedExecutorManager
80
+
81
+
82
+ def blocking_uppercase(value: str) -> str:
83
+ time.sleep(0.2)
84
+ return value.upper()
85
+
86
+
87
+ async def main() -> None:
88
+ manager = LeasedExecutorManager(
89
+ backend=ExecutorBackend.THREAD,
90
+ max_pools=2,
91
+ min_pools=1,
92
+ workers_per_pool=4,
93
+ name_prefix="quickstart-worker",
94
+ )
95
+
96
+ await manager.start()
97
+
98
+ try:
99
+ async with await manager.acquire(owner="quickstart") as lease:
100
+ result = await lease.run(blocking_uppercase, "hello leasepool")
101
+
102
+ print(result)
103
+ finally:
104
+ await manager.stop()
105
+
106
+
107
+ asyncio.run(main())
108
+ ```
109
+
110
+ ## Core usage model
111
+
112
+ A `LeasedExecutorManager` owns a bounded number of executor pools.
113
+
114
+ ```text
115
+ async application
116
+ -> LeasedExecutorManager
117
+ -> ExecutorLease
118
+ -> ThreadPoolExecutor / ProcessPoolExecutor
119
+ ```
120
+
121
+ The lease is the temporary right to submit work to one executor. Prefer the async
122
+ context-manager style because it returns the lease automatically:
123
+
124
+ ```python
125
+ async with await manager.acquire(owner="vendor-sdk-call") as lease:
126
+ result = await lease.run(sync_function, payload)
127
+ ```
128
+
129
+ Manual release is also available when your control flow requires it:
130
+
131
+ ```python
132
+ lease = await manager.acquire(owner="manual-flow")
133
+ try:
134
+ result = await lease.run(sync_function)
135
+ finally:
136
+ await lease.release()
137
+ ```
138
+
139
+ `lease.executor` is a safe proxy. It supports `submit()`, but prevents callers
140
+ from shutting down the internal executor or submitting after the lease expires or
141
+ has been released.
142
+
143
+ ## Backends
144
+
145
+ ### Thread backend
146
+
147
+ Use `backend="thread"` or `ExecutorBackend.THREAD` for blocking I/O:
148
+
149
+ - blocking vendor SDKs
150
+ - synchronous HTTP or database clients
151
+ - file I/O
152
+ - small blocking operations called from async services
153
+
154
+ ### Process backend
155
+
156
+ Use `backend="process"` or `ExecutorBackend.PROCESS` for CPU-heavy Python work
157
+ that should run across CPU cores:
158
+
159
+ ```python
160
+ manager = LeasedExecutorManager(
161
+ backend=ExecutorBackend.PROCESS,
162
+ max_pools=1,
163
+ min_pools=1,
164
+ workers_per_pool=4,
165
+ )
166
+ ```
167
+
168
+ Functions, arguments, and return values submitted to the process backend must be
169
+ picklable. Prefer top-level functions and simple serializable data. Do not submit
170
+ lambdas, nested functions, sockets, database clients, or async clients.
171
+
172
+ ### Interpreter backend
173
+
174
+ `backend="interpreter"` is reserved for Python 3.14+ `InterpreterPoolExecutor`.
175
+ On earlier Python versions, selecting it raises `UnsupportedBackendError`.
176
+
177
+ ## Backpressure and waiting
178
+
179
+ `max_pools` bounds the number of executor objects owned by one manager. If every
180
+ pool is leased, `acquire()` waits by default:
181
+
182
+ ```python
183
+ lease = await manager.acquire(owner="wait-for-capacity", timeout=2.0)
184
+ ```
185
+
186
+ Fail immediately with `wait=False`:
187
+
188
+ ```python
189
+ from leasepool import LeaseUnavailableError
190
+
191
+ try:
192
+ lease = await manager.acquire(owner="no-wait", wait=False)
193
+ except LeaseUnavailableError:
194
+ # Return HTTP 503, retry later, or enqueue elsewhere.
195
+ ...
196
+ ```
197
+
198
+ ## Lease expiry
199
+
200
+ Each lease has a soft lifetime and a grace period:
201
+
202
+ ```python
203
+ manager = LeasedExecutorManager(
204
+ backend="thread",
205
+ max_pools=2,
206
+ default_lease_seconds=300.0,
207
+ lease_grace_seconds=15.0,
208
+ )
209
+
210
+ lease = await manager.acquire(lease_seconds=30.0, owner="bounded-operation")
211
+ ```
212
+
213
+ After `lease_seconds + lease_grace_seconds`, new submissions through that lease
214
+ raise `LeaseExpiredError`. Existing work that was already submitted is left to the
215
+ underlying executor semantics.
216
+
217
+ ## Adaptive sizing
218
+
219
+ You can connect desired pool count to a runtime signal:
220
+
221
+ ```python
222
+ connected_devices: set[str] = set()
223
+
224
+ manager = LeasedExecutorManager(
225
+ backend="thread",
226
+ max_pools=10,
227
+ min_pools=1,
228
+ units_per_pool=10,
229
+ size_provider=lambda: len(connected_devices),
230
+ )
231
+
232
+ await manager.start()
233
+
234
+ connected_devices.add("device-1")
235
+ manager.notify_scale_changed()
236
+ ```
237
+
238
+ The target executor count is:
239
+
240
+ ```text
241
+ max(min_pools, ceil(size_provider() / units_per_pool))
242
+ ```
243
+
244
+ capped by `max_pools`. Idle executors above the target are shut down. Active
245
+ non-expired leases are not revoked just because the target shrinks.
246
+
247
+ ## WorkGrinder
248
+
249
+ `WorkGrinder` batches many async submitters into leased executor batches:
250
+
251
+ ```python
252
+ from leasepool import WorkGrinder
253
+
254
+ grinder = WorkGrinder(
255
+ executor_manager=manager,
256
+ batch_size_threshold=50,
257
+ max_wait_seconds=2.0,
258
+ lease_seconds=60.0,
259
+ )
260
+
261
+ await grinder.start()
262
+
263
+ try:
264
+ result = await grinder.submit(sync_function, payload, owner="item-1")
265
+ finally:
266
+ await grinder.stop(cancel_pending=True)
267
+ ```
268
+
269
+ Use:
270
+
271
+ - `await grinder.submit(...)` to queue work and wait for its result.
272
+ - `await grinder.enqueue(...)` to receive an `asyncio.Future` immediately.
273
+ - `grinder.submit_from_thread(...)` from non-async code or another OS thread.
274
+ - `grinder.stats()` for diagnostics from the event-loop thread.
275
+
276
+ ## Process worker log forwarding
277
+
278
+ Worker-process logs do not automatically flow through the parent process logger.
279
+ Enable forwarding when using the process backend:
280
+
281
+ ```python
282
+ import logging
283
+
284
+ from leasepool import LeasedExecutorManager, ProcessLoggingConfig
285
+
286
+ manager = LeasedExecutorManager(
287
+ backend="process",
288
+ max_pools=1,
289
+ min_pools=1,
290
+ workers_per_pool=2,
291
+ process_logging=ProcessLoggingConfig(
292
+ enabled=True,
293
+ level="INFO",
294
+ target_logger=logging.getLogger("leasepool.process"),
295
+ ),
296
+ )
297
+ ```
298
+
299
+ A convenience form is also available:
300
+
301
+ ```python
302
+ manager = LeasedExecutorManager(
303
+ backend="process",
304
+ max_pools=1,
305
+ forward_process_logs=True,
306
+ process_log_level="INFO",
307
+ )
308
+ ```
309
+
310
+ ## Diagnostics
311
+
312
+ ```python
313
+ print(manager.backend)
314
+ print(manager.available_count)
315
+ print(manager.leased_count)
316
+ print(manager.total_count)
317
+ print(manager.desired_executor_count())
318
+ print(manager.stats())
319
+ ```
320
+
321
+ `manager.stats()` includes backend, sizing, counts, workers per pool, and current
322
+ lease expiry information.
323
+
324
+ ## Examples
325
+
326
+ The `examples/` directory is designed as a learning path:
327
+
328
+ ```bash
329
+ python examples/00_quickstart_thread_backend.py
330
+ python examples/07_process_backend_cpu_work.py
331
+ python examples/08_work_grinder_submit.py
332
+ python examples/13_process_log_forwarding.py
333
+ python examples/14_complete_library_walkthrough.py
334
+ ```
335
+
336
+ For process-backend examples, run files directly instead of pasting them into a
337
+ REPL. `ProcessPoolExecutor` needs importable top-level functions.
338
+
339
+ See `README_EXAMPLES.md` for the complete example map.
340
+
341
+ ## What leasepool is not
342
+
343
+ `leasepool` is not a distributed task queue. It does not provide persistence,
344
+ remote workers, retries across machines, scheduling, or broker integration. It
345
+ manages local executor capacity inside one Python process.