Privacy Policy
Snippets index

  Asynchronous method call in Python using Threading

import threading, time

def f():
    print "f started"
    time.sleep(3)
    print "f finished"

threading.Thread(target=f).start()
import threading

thr = threading.Thread(target=foo, args=(), kwargs={})
thr.start() # will run "foo"
....
thr.is_alive() # will return whether foo is running currently
....
thr.join() # will wait till "foo" is done