Does this always go right
Carl.Wolff at imtech.nl
Carl.Wolff at imtech.nl
Tue Dec 5 10:04:31 EST 2006
Hello
question about copy vs deepcopy used in multithreaded context:
suppose the following program below:
the original dictionary is modified after the thread is started, the
thread works on a copied and deepcopied version of the original
dictionary. Is the dictionary named "originalcopy" isolated from changes
in original in multithreaded context?
The program reports no errors but I want to be really sure about this
Thanks
Carl.
<snip>
original = {}
originalcopy = {}
originaldeepcopy = {}
class checker(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
pass
def run(self):
while True:
for i in originaldeepcopy:
if originalcopy[i] == originaldeepcopy[i]:
pass
else:
print "error", originalcopy[i], "Not equal to",
originaldeepcopy[i]
i = 0
while i<1000:
original[i] = i
i = i + 1
originalcopy = copy.copy(original)
originaldeepcopy = copy.deepcopy(original)
test = checker()
test.start()
time.sleep(0.5)
while True:
i = 0
while i<1000:
original[i] = i*2
i = i + 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061205/60240f68/attachment.html>
More information about the Python-list
mailing list