Skip to content

Instantly share code, notes, and snippets.

@vishesh
Created December 17, 2011 22:55
Show Gist options
  • Save vishesh/1491699 to your computer and use it in GitHub Desktop.
Save vishesh/1491699 to your computer and use it in GitHub Desktop.
Decorator to make threads.
import threading
def threadify(func):
def run(*fargs, **fkwargs):
t = threading.Thread(target=func, args=fargs, kwargs=fkwargs)
t.start()
return run
@threadify
def function_a():
for i in range(100000):
if i%1000 is 0:
print ">>> A"
@threadify
def function_b():
for i in range(100000):
if i%1000 is 0:
print "<<< B"
function_a()
function_b()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment