I am trying to run two threads, each with an argument passed to it to process. However, it seems that the threads are running sequentially, not in parallel. Witness:
$ cat threading-stackoverflow.py
import threading
class CallSomebody (threading.Thread):
def __init__(self, target, *args):
self._target = target
self._args = args
threading.Thread.__init__(self)
def run (self):
self._target(*self._args)
def call (who):
while True:
print "Who you gonna call? %s" % (str(who))
a=CallSomebody(call, 'Ghostbusters!')
a.daemon=True
a.start()
a.join()
b=CallSomebody(call, 'The Exorcist!')
b.daemon=True
b.start()
b.join()
$ python threading-stackoverflow.py
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
Who you gonna call? Ghostbusters!
I would expect to have some lines return Ghostbusters! and others return The Exorcist!, however the Ghostbusters! lines go on forever. What must be refactored to have each thread get some processor time?