File tree Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,12 @@ def execute_thread(thread_num):
16
16
def main ():
17
17
for i in range (10 ):
18
18
thread = threading .Thread (target = execute_thread , args = (i , ))
19
+ # thread.daemon = True
19
20
thread .start ()
21
+ # thread.join()
20
22
21
- print ("Active threads: " , threading .active_count ())
22
-
23
- print ("thread objects: " , threading .enumerate ())
23
+ print ("Active threads: " , threading .active_count ())
24
+ print ("thread objects: " , threading .enumerate ())
24
25
25
26
if __name__ == '__main__' :
26
27
main ()
Original file line number Diff line number Diff line change
1
+ import random
2
+ import threading
3
+ import time
4
+
5
+
6
+ def count_up (num ):
7
+
8
+ global database , lock
9
+
10
+ lock .acquire ()
11
+
12
+ try :
13
+ time .sleep (random .randrange (3 ))
14
+ database .append (num )
15
+ finally :
16
+ lock .release ()
17
+
18
+
19
+ def main ():
20
+
21
+ global database , lock
22
+
23
+ lock = threading .Lock ()
24
+ database = []
25
+
26
+ threads = []
27
+ for i in range (15 ):
28
+ threads .append (threading .Thread (target = count_up , args = (i + 1 ,)))
29
+ threads [i ].start ()
30
+
31
+ for th in threads :
32
+ th .join ()
33
+
34
+ print (database )
35
+
36
+
37
+ if __name__ == '__main__' :
38
+ main ()
Original file line number Diff line number Diff line change
1
+ import curses
2
+
3
+ win = curses .initscr ()
4
+ key = win .getch ()
5
+
6
+ print (str (key ))
You can’t perform that action at this time.
0 commit comments