[issue27468] Erroneous memory behaviour for objects created in another thread
Peter Otten
report at bugs.python.org
Fri Jul 8 12:24:28 EDT 2016
Peter Otten added the comment:
Your code relies on the assumption that when the lambda is invoked the global t is still bound to the Thread instance you are starting. It seems that this is not always the case, and I don't see why it should be guaranteed either.
I don't know whether it's a good idea to store per-thread data in the Thread instance (have a look at threading.local()), but
def start_thread():
t = Thread(target=lambda: f(t))
t.obj = [0]
t.start()
for _ in range(n_threads):
start_thread()
will at least avoid the global.
----------
nosy: +peter.otten
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27468>
_______________________________________
More information about the Python-bugs-list
mailing list