D
D
DTPlayer2021-08-23 00:39:30
Python
DTPlayer, 2021-08-23 00:39:30

How to distribute data between threads in python?

There is a base, as well as software that allows you to enter the number of threads. How can one distribute the database so that other threads do not touch the data that one of the threads has taken over?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LXSTVAYNE, 2021-08-23
@DTPlayer

ThreadPool. I did not come up with a more complicated function, I just deduce it for clarity.

from multiprocessing.dummy import Pool as ThreadPool
import os


data = [i for i in range(100)]

with ThreadPool(os.cpu_count() - 1) as tp:
    tp.map(lambda x: print(x**2), data)

S
Stefan, 2021-08-23
@MEDIOFF

Other threads will not touch the data of other threads because the GIL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question