aboutsummaryrefslogtreecommitdiff
path: root/challenge-142/sgreen/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-142/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-142/sgreen/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-142/sgreen/python/ch-2.py b/challenge-142/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..1aebb131da
--- /dev/null
+++ b/challenge-142/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+import sys
+from time import sleep
+from threading import Thread
+
+
+def _sleep_sort(seconds):
+ sleep(float(seconds))
+ print(seconds)
+
+
+def main(inputs):
+ threads = []
+
+ if any(float(x) < 0 for x in inputs):
+ raise ValueError('You can sort negative numbers')
+
+ for seconds in inputs:
+ new_thread = Thread(target=_sleep_sort, args=(seconds,))
+ threads.append(new_thread)
+ new_thread.start()
+
+ for t in threads:
+ t.join()
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])