Answer the question
In order to leave comments, you need to log in
Multiprocessing django?
I have a loop like this:
name = 'something'
for hash, color in hashes:
ColorHashes.objects.create(name = name , hash = hash, color = color )
Answer the question
In order to leave comments, you need to log in
Try bulk_create
CHUNK_SIZE = 10000 # Подберите наиболее подходящий размер экспериментальным образом
def chunkify(items, chunk_size):
for i in range(0, len(items), chunk_size):
yield items[i:i+chunk_size]
name = 'something'
for chunk in chunkify(hashes, CHUNK_SIZE):
color_hashes = [ColorHashes(name=name , hash=hash, color=color) for hash, color in chunk]
ColorHashes.objects.bulk_create(color_hashes)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question