0

I want the following:

def start_job_and_return_string():
    start_job() #takes a while  
    return "job started"

by calling start_job_and_return_string I want to instantly get a string back. Later on the job will dump its results into the filesystem.

How can I accomplish this?

algebruh
  • 153
  • 1
  • 11

1 Answers1

1

One simple option is to use a thread:

from time import sleep
from threading import Thread

def start_job():
    sleep(1)
    print("all done!")

def start_job_and_return_string():
    Thread(target=start_job).start()
    return "job started"

print(start_job_and_return_string())

prints:

job started
all done!
Samwise
  • 68,105
  • 3
  • 30
  • 44