Y
Y
Yevgeni2018-07-26 19:57:23
Python
Yevgeni, 2018-07-26 19:57:23

How to return return before the execution of the loop inside the function is completed?

There is a function.
In it, a loop with sleep () pauses
after the loop should be returned with a string for example.
How, when calling a function, to immediately get the return value without waiting for the end of the loop, and the loop would continue its work in the background?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-07-26
@Yevgeni

Use a generator :

def f(x):
    for x in range(x):
        print('Hi!')
        yield x

for i in f(10):
    print(i)

D
Dimonchik, 2018-07-26
@dimonchik2013

well, you master Celery))
delay()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question