diff options
| author | Simon Green <mail@simon.green> | 2021-12-12 14:45:17 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2021-12-12 14:45:17 +1100 |
| commit | 277a6b908be328067cc11fb8353d5a88f91db2d8 (patch) | |
| tree | 6e4e5c0cb588b005bccb5ad0b99bb41e7967fa04 /challenge-142/sgreen/python/ch-2.py | |
| parent | a64c96703f1714a1598fe7fb90450a2763122643 (diff) | |
| download | perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.tar.gz perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.tar.bz2 perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.zip | |
sgreen solutions to challenge 142
Diffstat (limited to 'challenge-142/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-142/sgreen/python/ch-2.py | 29 |
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:]) |
