Skip to content

Instantly share code, notes, and snippets.

@puzzledsab
Created January 1, 2023 15:32
Show Gist options
  • Save puzzledsab/8cb29ac0c58adc343bb8836b67bc77f6 to your computer and use it in GitHub Desktop.
Save puzzledsab/8cb29ac0c58adc343bb8836b67bc77f6 to your computer and use it in GitHub Desktop.
import random
import hashlib
from queue import Queue
from threading import Thread
def md5calcq(md5, queue):
while True:
data = queue.get()
if not data:
break
md5.update(data)
data = random.randbytes(750000)
print("Start loop")
blockcount = 5000
threadcount = 4
threads = []
queues = []
for fi in range(threadcount):
q = Queue()
queues.append(q)
ct = Thread(target=md5calcq, args=(hashlib.md5(), q))
ct.start()
threads.append(ct)
for i in range(blockcount):
for fi in range(threadcount):
# filename = "testfile" + str(fi) + ".dat"
# with open(filename, "ab", buffering=0) as fout:
# fout.write(data)
queues[fi].put(data)
# md5calc(md5, data)
for fi in range(threadcount):
queues[fi].put(None)
for fi in range(threadcount):
threads[fi].join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment