Message269988
I create several objects in the main thread, and then spawn several threads that "take ownership" of one object each. Within that thread, the objects' attributes' values are not consistent. The bug only happens sometimes.
from threading import Thread
import pdb
n_threads = 8
def f(self):
self.obj[0] = 0
t = 0
while True:
if t != self.obj[0]:
pdb.set_trace() # should not happen
t += 1
self.obj[0] += 1
for _ in range(n_threads):
t = Thread(target=lambda: f(t))
t.obj = [0]
t.start()
Tested in Python 2.7.11 under Ubuntu 16.04 LTS and OS X. The bug does not happen in Python 3.5 or Python 3.6 .
Attached is a very similar program that exhibits the same issue, but which may be clearer and can sometimes be killed with Ctrl-C. |
|
Date |
User |
Action |
Args |
2016-07-08 14:54:31 | Adria Garriga | set | recipients:
+ Adria Garriga |
2016-07-08 14:54:31 | Adria Garriga | set | messageid: <1467989671.36.0.557850749029.issue27468@psf.upfronthosting.co.za> |
2016-07-08 14:54:31 | Adria Garriga | link | issue27468 messages |
2016-07-08 14:54:31 | Adria Garriga | create | |
|