-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueThreading.py
More file actions
42 lines (29 loc) · 954 Bytes
/
queThreading.py
File metadata and controls
42 lines (29 loc) · 954 Bytes
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
37
38
39
40
41
42
import threading
from queue import Queue
import time
import shutil
print_lock = threading.Lock()
def copy_op(file_data):
with print_lock:
print("Starting thread : {}".format(threading.current_thread().name))
mydata = threading.local()
mydata.ip, mydata.op = next(iter(file_data.items()))
shutil.copy(mydata.ip, mydata.op)
with print_lock:
print("Finished thread : {}".format(threading.current_thread().name))
def process_queue():
while True:
file_data = compress_queue.get()
copy_op(file_data)
compress_queue.task_done()
compress_queue = Queue()
output_names = [{'v1.mp4' : 'v11.mp4'},{'v2.mp4' : 'v22.mp4'}]
for i in range(2):
t = threading.Thread(target=process_queue)
t.daemon = True
t.start()
start = time.time()
for file_data in output_names:
compress_queue.put(file_data)
compress_queue.join()
print("Execution time = {0:.5f}".format(time.time() - start))