
Enviado em 14/02/2017 - 17:12h
Definitivamente: se existe o gil (global interpreter lock), como o uso de multi-threading pode acelerar um script em Python?
def ehPrimo(num):
if num % 2 == 0:
return False
end = round(num**0.5) + 1
for tmp in range(3, end, 2):
if num % tmp == 0:
return False
return True
import threading
div = 0
class verificadorPrimo(threadig.Thread):
def __init__(self, num, ini):
self.num = num
self.ini = ini
threading.Thread.__ini__(self)
def run(self):
global div
end = round(self.num ** 0.5) + 1
for tmp in range(self.ini, end, 4):
if div != 0:
break
if self.num % tmp == 0:
div = tmp
break
def ehPrimo(num):
global div
if num % 2 == 0:
return False
th1 = verificadorPrimo(num, 3)
th2 = verificadorPrimo(num, 5)
th1.start()
th2.start()
th1.join()
th2.join()
if div == 0:
return True
div = 0
return False
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
fusermount3 no Ubuntu 25.10 - mantenha o perfil do AppArmor
[Resolvido] dlopen(): error loading libfuse.so.2 AppImages require FUSE to run.
Criação de diretórios e aplicação de restrições de acesso no Linux
Podem me chamar de 1mbecil :) (10)
Monte o Google Drive como uma pasta remota no Linux (1)
Compartilhar ZEBRA ZD220 na rede (0)
diferença entre o Tor baixado pelo Gerenciador de Aplicativos e o Tor ... (8)









