summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-05-31 17:35:45 +0100
committerDamien George <damien.p.george@gmail.com>2016-06-28 11:28:52 +0100
commit63d05228a3173f079ea0a8f4fb11baa442351065 (patch)
treec2f0d9efc1e5d7af479536c8d3cc8d55d121d0c4
parent53562213c883ae4a89a3eff3eb4985716c5114c8 (diff)
downloadmicropython-63d05228a3173f079ea0a8f4fb11baa442351065.tar.gz
micropython-63d05228a3173f079ea0a8f4fb11baa442351065.zip
tests/thread: Allow thread_sleep1 to run without floating point.
-rw-r--r--tests/thread/thread_sleep1.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py
index 5f7534f6a1..032ec17543 100644
--- a/tests/thread/thread_sleep1.py
+++ b/tests/thread/thread_sleep1.py
@@ -3,26 +3,29 @@
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
- import utime as time
+ import utime
+ sleep_ms = utime.sleep_ms
except ImportError:
import time
+ sleep_ms = lambda t: time.sleep(t / 1000)
+
import _thread
lock = _thread.allocate_lock()
-n_thread = 16
+n_thread = 4
n_finished = 0
def thread_entry(t):
global n_finished
- time.sleep(t)
- time.sleep(2 * t)
+ sleep_ms(t)
+ sleep_ms(2 * t)
with lock:
n_finished += 1
for i in range(n_thread):
- _thread.start_new_thread(thread_entry, (i / 100,))
+ _thread.start_new_thread(thread_entry, (10 * i,))
# wait for threads to finish
while n_finished < n_thread:
- time.sleep(1)
+ sleep_ms(100)
print('done', n_thread)