Created
December 15, 2012 07:18
-
-
Save ambidextrousTx/4291900 to your computer and use it in GitHub Desktop.
Sleep sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Sleep sort using Python multiprocessing module | |
Idea: | |
- read a number n from a list | |
- spawn a new process | |
- within the process | |
- sleep n seconds | |
- print that number | |
Question - for how many numbers would it work? | |
""" | |
from multiprocessing import Process | |
import time | |
def worker(n): | |
time.sleep(n) | |
print n | |
def main(): | |
numbers = [4, 3, 6, 1, 5, 7, 0, 9, 6, 8] | |
for n in numbers: | |
p = Process(target = worker, args = (n, )) | |
p.start() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment