[PYTHON] Praktische Schlafsorte

sleep_sort.py



import threading
import time

sort_list = [1, 3, 6, 8, 10, 33, 44, 23]

def sort(lis):
    answer_list = []
    for num in lis:
        thread = threading.Thread(target=sleep,  args=(num, answer_list))
        thread.start()
    while (threading.active_count() > 1):
        time.sleep(0.1)
    print answer_list


def sleep(num, lis):
    time.sleep(num * 0.1)
    lis.append(num)


if __name__ == "__main__":
    sort(sort_list)

Recommended Posts

Praktische Schlafsorte
Sortieren
Sortierung einfügen
SelectionSort
[Python] Sortieren
Natürliche Sorte
Blasensorte
Blasensorte
[Neta] Thread-sichere Sleep-Sortierfunktion in Python (Threading)