Если вы хотите, чтобы функция выполнялась вечно, но не мешала вам выполнять другие функции, тогда вы можете использовать threads
.
. Вот пример с example_of_process
, который выполняется вечно, а затем основная программа с time.sleep(3)
import threading
import time
def example_of_process():
count = 0
while True:
print("count", count)
count += 1
time.sleep(1)
thread_1 = threading.Thread(target=example_of_process)
thread_1.daemon = True # without the daemon parameter, the function in parallel will continue even if your main program ends
thread_1.start()
# Now you can do anything else. I made a time sleep of 3s, otherwise the program ends instantly
time.sleep(3)