-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_thread.py
More file actions
executable file
·36 lines (24 loc) · 1.05 KB
/
circle_thread.py
File metadata and controls
executable file
·36 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Бесконечная карусель функций
from collections import deque
from time import sleep
def first():
print("First Function")
def second():
print("Second Function")
def third():
print("Third Function")
lst = [first, second, third]
def queue_loop(lst, pause=1):
"""Принимает список функций,
достает их по одной из списка,
запускает и отправляет обратно в конец очереди.
"""
queue = deque(lst) # Создаем очередь из переданного списка ф-й.
loop = True
while loop:
current = queue.popleft() # Достаем ф-ю из начала очереди
current() # Исполняем ее
queue.append(current) # Добавляем отработавшую ф-ю в конец очереди
sleep(pause) # Спим 1сек и повторяем
if __name__ == '__main__':
queue_loop(lst)