Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import threading
- def background(f):
- '''
- a threading decorator
- use @background above the function you want to run in the background
- '''
- def backgrnd_func(*a, **kw):
- threading.Thread(target=f, args=a, kwargs=kw).start()
- return backgrnd_func
- @background
- def call_function(fun_name, count):
- #This will print the count for every second
- for val in range(1, count+1):
- print("{} counts {}".format(fun_name, val))
- time.sleep(1)
- # start the background function
- # note that with the @background decorator
- # background function executes simultaneously
- print "My name is Amal. This is the main thread execution"
- counter("Background Function One", 6)
- counter("Background Function Two", 6)
- print "My name is Amal. The main thread reached here."
Add Comment
Please, Sign In to add comment