2 # -*- coding: utf-8 -*-
5 from multiprocessing import Process
6 from multiprocessing import Lock
7 from multiprocessing import Pool
10 """thread worker function"""
16 p = Process(target=worker, args=(i,))
22 print('parent process:', os.getppid())
23 print('process id:', os.getpid())
31 p = Process(target=f, args=('pascale',))
38 print('hello world', i)
45 Process(target=f, args=(lock, num)).start()
47 # sorties evt desordonnees
49 p = Process(target=worker, args=(i,)).start()
57 traceback.print_stack()
61 monPool=Pool(maxtasksperchild=1) #create a multiprocessing.Pool object
62 for l in range(num_cores):
63 print(" lct on core "+str(l) )
64 p= monPool.apply_async(g,(l,))
66 res = monPool.apply_async(g, (20,)) # runs in *only* one process
67 print res.get(timeout=1) # prints "400"
69 # evaluate "os.getpid()" asynchronously
70 res = monPool.apply_async(os.getpid, ()) # runs in *only* one process
71 print res.get(timeout=1) # prints the PID of that process
73 # launching multiple evaluations asynchronously *may* use more processes
74 multiple_results = [monPool.apply_async(os.getpid, ()) for i in range(4)]
75 print [res.get(timeout=1) for res in multiple_results]
79 if __name__ == '__main__':
86 print ('je suis dans main du run')