from joblib import Parallel, delayed
def func(v):
temp.append(v)
return
temp = []
Parallel(n_jobs=4)(delayed(func)(v) for v in range(10))
print temp
我想制作共享内存变量。但是temp的值是空的[]。我该怎么办?
对于其他方法,我尝试了pickle.dump并加载。但是存在锁定问题。请给我建议!
答案 0 :(得分:3)
from joblib import Parallel, delayed
def func(v):
return v
temp = Parallel(n_jobs=4)(delayed(func)(v) for v in range(10))
print temp
delayed
收集列表中func
返回的输出,并在完成后返回。
答案 1 :(得分:0)
您需要使用multiprocessing.Manager.list
,例如:
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
map_view.onCreate(savedInstanceState)
map_view.onResume()
MapsInitializer.initialize(context)
map_view.getMapAsync(this)
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker Title").snippet("Marker Description"))
val cameraPosition = CameraPosition.Builder().target(sydney).zoom(12f).build()
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
from joblib import Parallel, delayed
from multiprocessing import Manager
manager = Manager()
temp = manager.list()
def func(v, temp):
temp.append(v)
return
_ = Parallel(n_jobs=4)(delayed(func)(v, temp) for v in range(10))
:
temp[:]