diff options
author | Damien George <damien.p.george@gmail.com> | 2017-02-04 23:33:20 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-02-15 11:12:37 +1100 |
commit | 2847d7431d9334220445e93dc7af707821e80d5e (patch) | |
tree | b5fdc779efcad9c93146ea8e9e331e701f706f7c /tests/thread/stress_heap.py | |
parent | f2d732f4596064b3257abe571dc14ab61e02dec9 (diff) | |
download | micropython-2847d7431d9334220445e93dc7af707821e80d5e.tar.gz micropython-2847d7431d9334220445e93dc7af707821e80d5e.zip |
tests/thread: Replace busy waiting loops with a loop that sleeps.
Depending on the thread scheduler, a busy-wait loop can hog the CPU and
make the tests very slow. So convert such loops to loops that have an
explicit sleep, allowing the worker threads to do their job.
Diffstat (limited to 'tests/thread/stress_heap.py')
-rw-r--r-- | tests/thread/stress_heap.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/thread/stress_heap.py b/tests/thread/stress_heap.py index ac3ebe0491..5482a9ac6f 100644 --- a/tests/thread/stress_heap.py +++ b/tests/thread/stress_heap.py @@ -3,6 +3,10 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +try: + import utime as time +except ImportError: + import time import _thread def last(l): @@ -37,6 +41,6 @@ n_finished = 0 for i in range(n_thread): _thread.start_new_thread(thread_entry, (10000,)) -# busy wait for threads to finish +# wait for threads to finish while n_finished < n_thread: - pass + time.sleep(1) |