We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5356221 commit 63d0522Copy full SHA for 63d0522
1 file changed
tests/thread/thread_sleep1.py
@@ -3,26 +3,29 @@
3
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
4
5
try:
6
- import utime as time
+ import utime
7
+ sleep_ms = utime.sleep_ms
8
except ImportError:
9
import time
10
+ sleep_ms = lambda t: time.sleep(t / 1000)
11
+
12
import _thread
13
14
lock = _thread.allocate_lock()
-n_thread = 16
15
+n_thread = 4
16
n_finished = 0
17
18
def thread_entry(t):
19
global n_finished
- time.sleep(t)
- time.sleep(2 * t)
20
+ sleep_ms(t)
21
+ sleep_ms(2 * t)
22
with lock:
23
n_finished += 1
24
25
for i in range(n_thread):
- _thread.start_new_thread(thread_entry, (i / 100,))
26
+ _thread.start_new_thread(thread_entry, (10 * i,))
27
28
# wait for threads to finish
29
while n_finished < n_thread:
- time.sleep(1)
30
+ sleep_ms(100)
31
print('done', n_thread)
0 commit comments