background function in Python

Do something like this:

def function_that_downloads(my_args):
    # do some long download here

then inline, do something like this:

import threading
def my_inline_function(some_args):
    # do some stuff
    download_thread = threading.Thread(target=function_that_downloads, name="Downloader", args=some_args)
    download_thread.start()
    # continue doing stuff

You may want to check if the thread has finished before going on to other things by calling download_thread.isAlive()

Leave a Comment