repl.it
@MaxFratane/

OblongMarvelousPublishers

Python

No description

fork
loading
Files
  • main.py
main.py
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
import multiprocessing
import threading

NUM_THREADS = multiprocessing.cpu_count()
threads = []

def iniciaThreads(tamanho, funcao):
    _passo = int( (tamanho/NUM_THREADS) )
    _resto = tamanho%NUM_THREADS

    _process = None

    _limites = []
    _limites.append(0)
    _limites.append(_passo-1)

    for i in range(NUM_THREADS-1):
        _process =  threading.Thread(target=funcao, name=str(i), args=[_limites])
        _process.start()
        threads.append(_process)
        _limites[0] += _passo
        _limites[1] += _passo

    _limites[1] += _resto
    _process =  threading.Thread(target=funcao, name=str(NUM_THREADS-1), args=[_limites])
    _process.start()
    threads.append(_process)

def joinThreads(self):
    for i in self.threads:
        i.join()

iniciaThreads(30, lambda x: print(x))