Copy vs Deepcopy in multithreaded contexts
Carl.Wolff at imtech.nl
Carl.Wolff at imtech.nl
Wed Dec 6 04:51:50 EST 2006
Hello,
this issue is solved, no help needed.
Gtx
Carl.
----- Forwarded by Carl Wolff/IT/NL/Imtech on 06-12-2006 10:51 -----
Carl Wolff/IT/NL/Imtech wrote on 05-12-2006 22:55:20:
> 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/20061206/80aae1d1/attachment.html>
More information about the Python-list
mailing list