Created
December 17, 2011 22:55
-
-
Save vishesh/1491699 to your computer and use it in GitHub Desktop.
Decorator to make threads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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