1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

手習いsleepsort

Posted at
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)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?