Reputation: 1
For Example:
def abc():
for I in range(1,10000000000):
print(I)
def def():
for I in range(1,1000000000000):
print(I)
abc()
def()
How to let the abc()
keep running and not to wait abc()
to complete and jump to def()
Upvotes: 0
Views: 1233
Reputation: 334
You can use threads to perform this:
from threading import Thread
def abc():
for I in range(1,10000000000): print(I)
def other():
for I in range(1,10000000000): print(I)
abc_thread = Thread(target=abc)
abc_thread.start()
# This starts the abc() function and then immediately
# continues to the next line of code. This is possible because the
# function is executed on another thread separate from the main program's thread
other()
Also as a side note, I am not sure what your implementation of this will be but because you are new, I have to point out that it is bad practice to name your functions, classes, variables, etc. to the same name as a builtin python object. This will cause headaches later on when you will run into errors.
Upvotes: 1