jason
jason

Reputation: 3962

any alternative to celery for background tasks in python

I'm using flask and I was looking for any alternative in python which works like celery.

For eg:

@app.route('/')
def loop():
    for i in range(1000000):
        print(str(i))
        sys.stdout.write(str(i)+ '\n')
    return "done"  

instead of :

@celery.task(name="loop")
and
loop.delay()

Is there any python code I can use to achieve the same result instead of installing celery?

Btw, I tried :

 download_thread = threading.Thread(target=loop)
        download_thread.start()

But, I cannot see the data printed on console or anywhere on screen.

Upvotes: 0

Views: 1214

Answers (1)

ryche
ryche

Reputation: 2094

Try to do it this way:

def foo():
    for i in range(1000000):
        print(str(i))
        sys.stdout.write(str(i)+ '\n')

@app.route('/')
def loop():
    download_thread = threading.Thread(target=foo)
    download_thread.start()

Upvotes: 1

Related Questions