You can use events: http://docs.python.org/2/library/threading.html
I tested this and it works. It also syncs everything. You should avoid changing / reading the same variables in different threads without synchronizing them.
#!/usr/bin/python from threading import Thread from threading import Event import time import itertools import sys def b(event): for j in itertools.cycle('/-\|'): if not event.is_set(): sys.stdout.write(j) sys.stdout.flush() time.sleep(0.1) sys.stdout.write('\b') else: return def a(event):
Associated with 'kwargs', from Python docs (URL at the beginning of the post):
class threading.Thread(group=None, target=None, name=None, args=(), kwargs={}) ... kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
Mihai source share