1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| from multiprocessing import Process, Manager
import os
class Foo:
def __init__(self):
self.f = 1
self.f2 = 1
self.mylist=[0,1,2,3,4,5,6]
def foo(self):
self.f += 1
def g1(ns):
f = ns.f
f.foo()
print(f)
ns.f = f
def Otherprocess(ns):
s = ns.f
print("Process2 :")
print(s.f)
s.mylist=[0]
"""while True:
s.f2+=1"""
ns.f = s
if __name__ == '__main__':
mgr = Manager()
mgr.register('Foo', Foo)
ns = mgr.Namespace()
ns.f = Foo()
print(ns.f)
p = Process(target=g1, args=(ns,))
p.start()
p.join()
p2 = Process(target=Otherprocess, args=(ns,))
p2.start()
p.join()
p2.join()
print (ns.f.mylist) |
Partager