8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6802ef commit a0e887eCopy full SHA for a0e887e
experiments/threads.py
@@ -0,0 +1,26 @@
1
+import threading
2
+import time
3
+import random
4
+
5
6
+def execute_thread(thread_num):
7
+ print("Thread {} sleeps at {}.".format(thread_num, time.strftime("%H:%M:%S", time.gmtime())))
8
9
+ sleep_time = random.randint(1, 5)
10
11
+ time.sleep(sleep_time)
12
13
+ print("Thread {} stops sleeping at {}.".format(thread_num, time.strftime("%H:%M:%S", time.gmtime())))
14
15
16
+def main():
17
+ for i in range(10):
18
+ thread = threading.Thread(target=execute_thread, args=(i, ))
19
+ thread.start()
20
21
+ print("Active threads: ", threading.active_count())
22
23
+ print("thread objects: ", threading.enumerate())
24
25
+if __name__ == '__main__':
26
+ main()
0 commit comments