10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-21 11:53:32 +01:00

Version:1.1.52

This commit is contained in:
Anthony Scemama 2010-10-02 21:19:04 +02:00
parent 969e31490b
commit 0da7952476
2 changed files with 31 additions and 15 deletions

View File

@ -24,6 +24,7 @@
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
NTHREADS=3
def strip(x):
return x.strip()
@ -128,25 +129,40 @@ def put_info(text,filename):
import cPickle as pickle
import os, sys
def fork_and_pickle(f,filename,text):
def parallel_loop(f,source):
pidlist = {}
src = [ [] for i in xrange(NTHREADS) ]
index = 0
for i in source:
index = index+1
if index == NTHREADS:
index = 0
src[index].append(i)
for thread_id in xrange(1,NTHREADS):
fork = os.fork()
if fork == 0:
break
else:
import time
time.sleep(1)
pidlist[i] = fork
thread_id = 0
print "fork : ", fork, thread_id
for filename, text in src[thread_id]:
result = f(filename,text)
file = open('%s.pickle'%filename,'w')
pickle.dump(result,file,-1)
file.close()
sys.exit(0)
else:
return fork
def parallel_loop(f,source):
pidlist = {}
for filename, text in source:
pidlist[filename] = fork_and_pickle( f, filename, text )
for i in xrange(NTHREADS):
os.waitpid(pidlist[i],0)
result = []
for filename,text in source:
os.waitpid(pidlist[filename],0)
file = open('%s.pickle'%filename,'r')
data = pickle.load(file)
file.close()

View File

@ -1 +1 @@
version = "1.1.51"
version = "1.1.52"