We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 094a0dd commit 2e4cdaeCopy full SHA for 2e4cdae
1 file changed
tests/thread/thread_qstr1.py
@@ -0,0 +1,34 @@
1
+# test concurrent interning of strings
2
+#
3
+# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
4
+
5
+import _thread
6
7
+# function to check the interned string
8
+def check(s, val):
9
+ assert type(s) == str
10
+ assert int(s) == val
11
12
+# main thread function
13
+def th(base, n):
14
+ for i in range(n):
15
+ # this will intern the string and check it
16
+ exec("check('%u', %u)" % (base + i, base + i))
17
18
+ with lock:
19
+ global n_finished
20
+ n_finished += 1
21
22
+lock = _thread.allocate_lock()
23
+n_thread = 4
24
+n_finished = 0
25
26
+# spawn threads
27
+for i in range(n_thread):
28
+ _thread.start_new_thread(th, (i * 1000, 1000))
29
30
+# busy wait for threads to finish
31
+while n_finished < n_thread:
32
+ pass
33
34
+print('pass')
0 commit comments