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):
1616def main ():
1717 for i in range (10 ):
1818 thread = threading .Thread (target = execute_thread , args = (i , ))
19+ # thread.daemon = True
1920 thread .start ()
21+ # thread.join()
2022
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 ())
2425
2526if __name__ == '__main__' :
2627 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