I want an optimized way to save the binary data in a file by splitting it into 4 parts. The problem is that when I get the data from the queue, it will save it in an unorganized way.
Note: this is a sample of binary data. The binary file is much bigger than this.
import multiprocessing
queue1 = multiprocessing.Queue()
queue2 = multiprocessing.Queue()
queue3 = multiprocessing.Queue()
queue4 = multiprocessing.Queue()
data = [b'\xff\xd8\xff\xe0\x00', b'\x10JFIF', b'\x00\x01\x01\x01\x00',
b'H\x00H\x00\x00', b'\xff\xdb\x00C\x00', b'\x06\x04\x05\x06\x05',
b'\x04\x06\x06\x05\x06', b'\x07\x07\x06\x08\n', b'\x10\n\n\t\t', b'\n\x14\x0e\x0f\x0c']
data2 = [b'\x10\x17\x14\x18\x18', b'\x17\x14\x16\x16\x1a', b'\x1d%\x1f\x1a\x1b', b'#\x1c\x16\x16 ',
b", #&'", b')*)\x19\x1f', b'-0-(0', b'%()(\xff', b'\xdb\x00C\x01\x07', b'\x07\x07\n\x08\n']
data3 = [b'\x13\n\n\x13(', b'\x1a\x16\x1a((', b'(((((', b'(((((', b'(((((', b'(((((', b'(((((', b'(((((',
b'(((((', b'(((((']
data4 = [b'(((((', b'(((\xff\xc2', b'\x00\x11\x08\x04L', b'\x029\x03\x01"', b'\x00\x02\x11\x01\x03',
b'\x11\x01\xff\xc4\x00', b'\x1c\x00\x01\x00\x02', b'\x03\x01\x01\x01\x00',
b'\x00\x00\x00\x00\x00', b'\x00\x00\x00\x00\x04']
def put_data(data, data2, data3, data4):
i = 0
while True:
if i < 10:
queue1.put(data[i])
queue2.put(data2[i])
queue3.put(data3[i])
queue4.put(data4[i])
i = i + 1
else:
break
def get_data():
i = 0
with open("myTest2.jpg", 'wb') as f:
while True:
if i < 10:
content = queue1.get()
f.write(content)
content = queue2.get()
f.write(content)
content = queue3.get()
f.write(content)
content = queue4.get()
f.write(content)
i = i + 1
# print(i)
if __name__ == '__main__':
p1 = multiprocessing.Process(target=put_data(data, data2, data3, data4))
p2 = multiprocessing.Process(target=get_data())
p1.start()
p2.start()
p1.join()
p2.join()