Show HN: Asyncpal: Preemptive concurrency and parallelism for sporadic workloads
2 by alexrustic | 0 comments on Hacker News.
Hi HN ! Alex here. I'm excited to show you Asyncpal ( https://ift.tt/ctMg4wA ), 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/BQHnJKp [2] https://ift.tt/6trLY83 [3] https://ift.tt/n4WCRDJ... (related) [4] https://ift.tt/xMQ0NVe [5] https://ift.tt/3akSfls [6] https://ift.tt/CpX9JKO...
2 by alexrustic | 0 comments on Hacker News.
Hi HN ! Alex here. I'm excited to show you Asyncpal ( https://ift.tt/ctMg4wA ), 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/BQHnJKp [2] https://ift.tt/6trLY83 [3] https://ift.tt/n4WCRDJ... (related) [4] https://ift.tt/xMQ0NVe [5] https://ift.tt/3akSfls [6] https://ift.tt/CpX9JKO...