forked from l3uddz/plex_autoscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_threads.py
36 lines (29 loc) · 1022 Bytes
/
test_threads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import time
from threads import Thread, PriorityLock
############################################################
# MISC
############################################################
def test_thread(lock, priority):
lock.acquire(priority)
try:
print("Hello from priority: %s" % str(priority))
time.sleep(5)
finally:
lock.release()
print("Finished priority: %s" % str(priority))
############################################################
# MAIN
############################################################
if __name__ == "__main__":
lock = PriorityLock()
threads = Thread()
for pos in reversed(range(0, 100)):
threads.start(test_thread, args=[lock, pos], track=True)
print("Started first batch of threads")
time.sleep(15)
for pos in reversed(range(0, 100)):
threads.start(test_thread, args=[lock, pos], track=True)
print("Started second batch of threads")
threads.join()
print("All threads finished")