Message283165
Calling copy.copy on a threading.local subclass copies attributes over correctly in Python 2.7, but creates an empty object in Python 3.3-3.5 and fails with a pickle-related error in 3.6.
Marking this as a release blocker and assigning to Ned because this appears to be a regression in 3.6. However, given that the behavior in previous Python 3 versions isn't very useful either, I'd personally not want to block 3.6 on it.
I haven't yet looked at code to figure out what is causing the differences in behavior. I couldn't find any tracker issues related to copying or pickling threading.local objects, but may have missed something.
$ cat thread_local_copy.py
import copy
import threading
class Obj(threading.local):
def __init__(self):
self.x = 3
o = Obj()
o2 = copy.copy(o)
assert hasattr(o2, 'x')
$ python2.7 thread_local_copy.py
$ python3.3 thread_local_copy.py
Traceback (most recent call last):
File "thread_local_copy.py", line 10, in <module>
assert hasattr(o2, 'x')
AssertionError
$ python3.4 thread_local_copy.py
Traceback (most recent call last):
File "thread_local_copy.py", line 10, in <module>
assert hasattr(o2, 'x')
AssertionError
$ python3.5 thread_local_copy.py
Traceback (most recent call last):
File "thread_local_copy.py", line 10, in <module>
assert hasattr(o2, 'x')
AssertionError
$ ./python.exe -V
Python 3.6.0+
$ ./python.exe thread_local_copy.py
Traceback (most recent call last):
File "thread_local_copy.py", line 9, in <module>
o2 = copy.copy(o)
File "/Users/Jelle/code/cpython/Lib/copy.py", line 96, in copy
rv = reductor(4)
TypeError: can't pickle Obj objects |
|
Date |
User |
Action |
Args |
2016-12-14 06:09:48 | JelleZijlstra | set | recipients:
+ JelleZijlstra, ned.deily |
2016-12-14 06:09:48 | JelleZijlstra | set | messageid: <1481695788.41.0.793591769474.issue28967@psf.upfronthosting.co.za> |
2016-12-14 06:09:48 | JelleZijlstra | link | issue28967 messages |
2016-12-14 06:09:47 | JelleZijlstra | create | |
|