diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-12-13 10:43:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-13 10:43:23 +0000 |
| commit | 108219d380b0236dd41ebba9392cc3abe3907c02 (patch) | |
| tree | 27e4a40e68f46832acb3a31333d58ae886773b29 /challenge-142/sgreen/python/ch-2.py | |
| parent | add40b4474438eec3192c5e2918d3ace4d842568 (diff) | |
| parent | 277a6b908be328067cc11fb8353d5a88f91db2d8 (diff) | |
| download | perlweeklychallenge-club-108219d380b0236dd41ebba9392cc3abe3907c02.tar.gz perlweeklychallenge-club-108219d380b0236dd41ebba9392cc3abe3907c02.tar.bz2 perlweeklychallenge-club-108219d380b0236dd41ebba9392cc3abe3907c02.zip | |
Merge pull request #5367 from simongreen-net/swg-142
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:]) |
