''' threads.py Jeff Ondich, 15 November 2010 Simple example of threaded code. Beware the race condition. (Take a close look at the output. Is it all a's or all b's on every line? Or does it get mixed up?) ''' from threading import * class FightingThread(Thread): def __init__(self, symbol): Thread.__init__(self) self.symbol = symbol def run(self): for j in range(1000): for k in range(len(gSharedList)): gSharedList[k] = self.symbol print gSharedList gSharedList = ['x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'] threadA = FightingThread('a') threadB = FightingThread('b') threadA.start() threadB.start()