Package to monitor and throttle multiprocessing processes.
Project description
mp_throttle
A Python package to monitor and throttle multiprocessing processes.
Use case:
This package can be used to control and monitor Pythons multiprocessing processes. The central Throttle class can be used to monitor the current and the mean frequency of processes and/or to throttle your processes to execute a limited times per second. This can be used to limit the server requests of a multi-process web crawler.
Example:
import multiprocessing
import mp_throttle
import time
def work(tank):
while not tank.kill_flag.is_set():
# Block until 'fuel' is available.
tank.await_fuel()
# do something
return
# Limit the processes to 4 per 1 second, by providing 4 'fuel' per second.
throttle = mp_throttle.Throttle(4,1)
workerpool = multiprocessing.Pool(processes=4, initializer=work, initargs=(throttle,))
throttle.start()
time.sleep(5)
# Stops the processes and return stats:
runtime, total_processes, mean_frequency, mean_processes_per_second = throttle.stop()
print("Runtime: {}".format(runtime))
print("Total: {}".format(total_processes))
print("Mean frequency: {}".format(mean_frequency))
print("Processes per second: {}".format(mean_processes_per_second))
Output:
>>> Runtime: 5.027516841888428
>>> Total: 20
>>> Mean frequency: 0.25046865940093993
>>> Processes per second: 3.9925154803469485
Installation:
To install mp_throttle, simply use pip:
pip install mp_throttle
Documentation:
For the full documentation see docs.elpunkt.eu
How to Contribute:
- Test mp_throttle and open an issue to report a bug or discuss a feature idea.
- Give general feedback on the code and the package structure. Since this is my first python package, I'm sure there is a lot to feedback on:)
- Fork the repository and make your changes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mp_throttle-0.0.2.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for mp_throttle-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ae5adca71c589200e3693e146bdb2f1ee46e07e8cad7aa0d17d2a0903e5d79b |
|
MD5 | 824e99b1731d994c3dc9792d913d5b4e |
|
BLAKE2b-256 | b24e37d6586aa8b3e7282cca4c5ba03e4b30825c439e0b73eddf81247fd09a5b |