python - Object method as multiprocessing.Process target -
i'm tinkering threads, shed light what's going on here?
from multiprocessing import process time import sleep class thing(object): def __init__(self): print "__init__:", id(self) self.a = 100 self.b = 200 def run(self): while true: sleep(5) print id(self.a), self.a, '*', id(self.b), self.b i open script via python -i , do:
t = thing() p = process(target=t.run) p.start() # thread starts running , reporting ids every 5 seconds # if do.. t.a = 500 # address of `t.a` changes (using `id()`) , thread still reports 100. i understand expecting work mean sketchy thread communication, looks @ point there 2 thing() objects, 1 available me , 1 inside process(). when copied?
and important:
how change value of self.a inside process()?
in situation using processes not threads, need inter process communication. can achieve queues. see http://docs.python.org/dev/library/multiprocessing.html, 17.2.1.3. exchanging objects between processes.
Comments
Post a Comment