擅长:python、mysql、java
<p>所以我通过重新编写代码和删除池(根据J.F.Sebastian的评论)来完成这项工作。</p>
<p>在伪代码中:</p>
<pre><code>initialize the shared array
determine step size
create an empty list of jobs
create the process, pass it the kwargs, and append it to the job list
start the jobs
join the jobs
</code></pre>
<p>如果这对任何谷歌用户都有帮助的话,下面是代码:</p>
<pre><code>#Initialize the ctypes array
init(array)
#Remove the reference to the array (to preserve memory on multiple iterations.
del array
step = y // cores
jobs = []
if step != 0:
for i in range(0,y,step):
p = multiprocessing.Process(target=stretch,args= (shared_arr,slice(i, i+step)),kwargs=options)
jobs.append(p)
for job in jobs:
job.start()
for job in jobs:
job.join()
</code></pre>