Skip to content

Instantly share code, notes, and snippets.

@tmiz
Created May 19, 2011 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmiz/981229 to your computer and use it in GitHub Desktop.
Save tmiz/981229 to your computer and use it in GitHub Desktop.
sleepsort.py
# sleep sort
import threading
import time
class SleepAndAppend(threading.Thread):
def __init__(self, value, targetList):
threading.Thread.__init__(self)
self.value = value
self.targetList = targetList
def run(self):
time.sleep(self.value * 0.01)
self.targetList.append(self.value)
def sleepSort(aList):
targetList = []
threadList = []
for a in aList:
th = SleepAndAppend(a, targetList)
th.start()
threadList.append(th)
for th in threadList:
th.join();
return targetList
aList = [23,1,53,3,1,3,6,13,3,6,1,3,7,1,3,6,1,3,7,133,63,137]
print sleepSort(aList)
@tmiz
Copy link
Author

tmiz commented May 20, 2011

check this snippet using coruitine by miyagawa san
https://gist.github.com/982113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment