Run function in multiple processes
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
gy-multiprocessing
Installation
via Github
pip install git+https://github.com/guangyu-he/py-multiprocessing@main
via PyPI
pip install gy-multiprocessing
Usage
- initialize a mp pool with a dictionary of lists of processes (and their output) and their runtimes
- generate a mp object inside the loop you want to run parallel
- run the function with the given arguments and callback the mp pool
Examples
no returned value from the function required
import gy_multiprocessing.multiprocessing as gymp
def your_func(a_string: str):
print(a_string)
if __name__ == '__main__':
mp_pool = gymp.init()
outer_loop_times = 10 # for example
for current_loop_index in range(outer_loop_times):
# your number of loop tasks that want to run parallel
# optional arguments:
# process_name: the name of the process
# max_threads: the number of max parallel processes
# process_log: whether to show the process pool log when process is running to the end
mp = gymp.multi_process.MultiProcess(mp_pool, outer_loop_times, current_loop_index)
# your running arguments, must be tuple
args = (str(outer_loop_times),)
# run function using arguments and get callback mp_pool
mp_pool = mp.run(your_func, args)
need to check the returned value from the function
import gy_multiprocessing.multiprocessing as gymp
def your_func(a_string: str):
print(a_string)
if __name__ == '__main__':
mp_pool = gymp.init()
outer_loop_times = 10 # for example
for current_loop_index in range(outer_loop_times):
# your number of loop tasks that want to run parallel
# using withqueue method to show returned value in the console
# optional arguments:
# process_name: the name of the process
# max_threads: the number of max parallel processes
# process_log: whether to show the process pool log when process is running to the end
mp = gymp.multi_process_withqueue.MultiProcess(mp_pool, outer_loop_times, current_loop_index)
# your running arguments, must be tuple
args = (str(outer_loop_times),)
# run function using arguments and get callback mp_pool
mp_pool = mp.run(your_func, args)
2022©Guangyu He, for further support please contact author.
Email: me@heguangyu.net
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gy_multiprocessing-0.1.1.tar.gz.
File metadata
- Download URL: gy_multiprocessing-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c0e46ae8ddf246ff6e6085d0be7f126d6e8f9a0b68b91ecf7e2de47f9ff1c7
|
|
| MD5 |
5b952965111c481700a5eb82c37da2f1
|
|
| BLAKE2b-256 |
f206c51fee07dc151e036cc0e2fc4d1fb63990221db3d3ce60251ff63cae162e
|