diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-12-07 17:08:53 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-12-07 17:08:53 -0500 |
| commit | f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4 (patch) | |
| tree | a7162c0c01b282684f159edc35a2f940a8a77e38 /challenge-142/roger-bell-west/python/ch-2.py | |
| parent | 038f05c9243b83b2b654559b5005506bc6a3fc2b (diff) | |
| parent | 59dd7ccf422a3b10f31e3ad2cc9a2704ce6b40e0 (diff) | |
| download | perlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.tar.gz perlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.tar.bz2 perlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-142/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-142/roger-bell-west/python/ch-2.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-142/roger-bell-west/python/ch-2.py b/challenge-142/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..f377b7678a --- /dev/null +++ b/challenge-142/roger-bell-west/python/ch-2.py @@ -0,0 +1,35 @@ +#! /usr/bin/python3 + +import unittest + +from random import randint +import multiprocessing as mp +from time import sleep + +def sleeper(x,q): + sleep(float(x)/500.0) + q.put(x) + +def sleepsort(n): + q=mp.SimpleQueue() + pq=[] + for i in n: + p=mp.Process(target=sleeper,args=(i,q)) + p.start() + pq.append(p) + for p in pq: + p.join() + r=[] + while not q.empty(): + r.append(q.get()) + return r + +class TestSleepsort(unittest.TestCase): + + def test_ex1(self): + a=[] + for i in range(10): + a.append(randint(1,100)) + self.assertEqual(sleepsort(a),sorted(a),'example 1') + +unittest.main() |
