multiprocessing
multiprocessing — Process-based parallelism — Python 3.7.4 documentation
multiprocessing --- プロセスベースの並列処理 — Python 3.7.4 ドキュメント
Examples
`#41 - multiprocessing : Unidata Developer's Blog
plotting figures
code:python
import multiprocessing as mp
with mp.Pool(processes=4) as pool:
pool.map(plot_datasets,cat.datesets-10:) pool.close()
pool.join()
`#82 - Multiprocessing : Unidata Developer's Blog
code:pyhon
import multiprocessing as mp
for fname in data_path.glob("*.mts")
pool.apply_async(get_station_means,args=(fname,),callback=record_means)
pool.close()
pool.join()
`#126 - Queue with Multiprocessing : Unidata Developer's Blog writing data to a sigle file
`#127 - Multiprocessing and Managed Dictionaries : Unidata Developer's Blog
code:python
import multiprocessing as mp
from multiprocessing import Manager
def calculate_pw(d,station,timestamp):
def main():
manager = Manager()
results = manager.dict()
pool = mp.Pool(4)
jobs = []
stations = ....
t=datetime(2020,3,19)
for station in stations:
job=pool.apply_async(calculate_pw,(results,station,t))
jobs.append(job)
for job in jobs:
job.get()
pool.close()
pool.join()
if __name__ = '__main__':
main()
code:python
with mp.get_context("spawn").Pool(4) as p:
p.map(myplot, range(n))
雨の中、Cを書かずにPythonで並列計算をする人間がいてもいい。自由とはそういうものだ。 - Qiita
python - Easy parallelization of numpy.apply_along_axis()? - Stack Overflow
Tip
apply_async
The order of the results is not guaranteed to be the same as the order of the calls to Pool.apply_async.