Skip to content

Commit 63d0522

Browse files
committed
tests/thread: Allow thread_sleep1 to run without floating point.
1 parent 5356221 commit 63d0522

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tests/thread/thread_sleep1.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
44

55
try:
6-
import utime as time
6+
import utime
7+
sleep_ms = utime.sleep_ms
78
except ImportError:
89
import time
10+
sleep_ms = lambda t: time.sleep(t / 1000)
11+
912
import _thread
1013

1114
lock = _thread.allocate_lock()
12-
n_thread = 16
15+
n_thread = 4
1316
n_finished = 0
1417

1518
def thread_entry(t):
1619
global n_finished
17-
time.sleep(t)
18-
time.sleep(2 * t)
20+
sleep_ms(t)
21+
sleep_ms(2 * t)
1922
with lock:
2023
n_finished += 1
2124

2225
for i in range(n_thread):
23-
_thread.start_new_thread(thread_entry, (i / 100,))
26+
_thread.start_new_thread(thread_entry, (10 * i,))
2427

2528
# wait for threads to finish
2629
while n_finished < n_thread:
27-
time.sleep(1)
30+
sleep_ms(100)
2831
print('done', n_thread)

0 commit comments

Comments
 (0)