Show HN: Asyncpal: Preemptive concurrency and parallelism for sporadic workloads Hi HN ! Alex here. I'm excited to show you Asyncpal ( https://ift.tt/BUWH8np ), a Python library for parallelism [1] and preemptive concurrency [2] tailored for sporadic workloads [3]. I've been working on a private project where it would be convenient to have asynchronous versions of some operations without using `async/await` [4]. Besides `async/await`, which represents cooperative concurrency via the `asyncio` package, Python also provides preemptive concurrency through its `threading` package. Additionally, the `concurrent.futures` package builds upon the `threading` package to provide a thread pool [5], which is the design pattern my project needed for managing concurrent tasks. Although a thread pool is the right tool for the problems it solves, its creation and usage involve the allocation of resources that must be properly released. For this reason, it is recommended to use a thread pool with a context manager [6] to ensure that resources are properly released once the pool executor has finished its tasks. However, this strategy can introduce overhead in programs that sporadically submit tasks to a thread pool, as multiple pools may be created and destroyed throughout the execution of these programs. Maintaining one or a few thread pools for the duration of a program can be an effective solution, assuming these thread pools can automatically shrink after workers have been idle for a short period defined by the programmer. I developed Asyncpal to meet the requirements and extended it with processes to achieve parallelism. For more details about this project, please refer to the README. You can download the lightweight package on PyPI, try the examples provided in the README, or run the tests on your machine. Let me know what you think about this project. [1] https://ift.tt/q4Uv6Do [2] https://ift.tt/bOrHMB2 [3] https://ift.tt/p2aLMlw... (related) [4] https://ift.tt/K6CqcSv [5] https://ift.tt/MQEFjLT [6] https://ift.tt/axz5jvc... https://ift.tt/BUWH8np August 30, 2024 at 11:12PM
0 Comments