修改czcore多进程为pool模式,修复多进程不返回结果问题

这个提交包含在:
2023-04-06 23:24:47 +08:00
父节点 6845ee0834
当前提交 cc9a89d40c
+28 -20
查看文件
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from multiprocessing import Process
from multiprocessing import Process, Pool
from functools import partial
from os import system
import numpy as np
from pyat.AcousticPara import GetEnv, Coord
@@ -296,6 +297,18 @@ def call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi, isPlot=False):
czdetail.reflectCz = []
return Pos.r.range, Pos.r.depth, TL[0, 0, :, :], bathm, Rays, czdetail
def child(database, freq, lat, lon, sd, rd, i):
descripts = ["正北方向", "东北方向", "正东方向", "东南方向", "正南方向", "西南方向", "正西方向", "西北方向"]
theta = np.arange(0, 359, 45)
[bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=theta[i])
if np.mean(bathm.d) < 2000:
# 不会出现会聚区
ddd=[]
return None
else:
ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi=theta[i],isPlot=True)
czdetail.descript = descripts[i]
return CzData(theta[i], ranges, depths, TL, bathym, Rays, czdetail)
def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPlot=False):
sd = np.array([sourceDepth]) # Source depth
@@ -303,29 +316,17 @@ def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPl
results = []
ranges, depths, TL, bathym, Rays = [], [], [], [], []
def child(i):
descripts = ["正北方向", "东北方向", "正东方向", "东南方向", "正南方向", "西南方向", "正西方向", "西北方向"]
theta = np.arange(0, 359, 45)
[bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=theta[i])
if np.mean(bathm.d) < 2000:
# 不会出现会聚区
ddd=[]
else:
ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi=theta[i],isPlot=True)
czdetail.descript = descripts[i]
results.append(CzData(theta[i], ranges, depths, TL, bathym, Rays, czdetail))
return results
def child_0(interval):
results=child(interval)
return results
# def child_0(interval):
# czdata=child(interval)
# return czdata
''' 计算单个方向的会聚区 '''
if azi != None:
[bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=azi)
if np.mean(bathm.d) < 2000:
return results
return None
else:
ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base,
ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi,
isPlot=isPlot)
czdetail.descript = "{:.1f}°方向".format(azi)
results.append(CzData(0, ranges, depths, TL, bathym, Rays, czdetail))
@@ -337,7 +338,14 @@ def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPl
# file_cz_data.write("各个方位都不会出现会聚区")
return results
else:
pool = Pool(processes=8)
applyResults = []
for pi in range(8):
pi=Process(target=child_0,args=(pi,))
pi.start()
applyResults.append(pool.apply_async(partial(child, database, freq, lat, lon, sd, rd), (pi,)))
# pi=Process(target=child_0,args=(pi,))
# pi.start()
pool.close()
pool.join()
for applyResult in applyResults:
results.append(applyResult.get())
return results