Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import multiprocessing, random
- class maquina(multiprocessing.Process):
- def __init__(self,id,saida):
- self.id = id
- self.saida = saida
- multiprocessing.Process.__init__(self)
- def run(self):
- while self.id.empty() == False:
- re = []
- resultado = self.id.get()
- re.append(resultado[1])
- if resultado[0] != 5:
- re.append('Sucess')
- else:
- re.append('Loss')
- print(re)
- self.saida.put(re)
- self.id.task_done()
- class produto(object):
- def __init__(self):
- self.sucesso = random.randint(1,5)
- self.tempo = random.randint(2,7)
- def vai(self):
- return (self.sucesso,self.tempo)
- if __name__ == '__main__':
- tempo = 0
- pfeitos = 0
- total = 0
- produtos = 60
- horas = 10
- fila = multiprocessing.JoinableQueue()
- saida = multiprocessing.Queue()
- ms = []
- for c in range(horas):
- for c in range(produtos):
- fila.put(produto().vai())
- for c in range(3):
- ms.append(maquina(fila,saida))
- for c in ms:
- c.start()
- for c in ms:
- c.join()
- input('next')
- while saida.empty() != True and tempo < 60*horas:
- pfinal = saida.get()
- tempo += pfinal[0]
- total+= 1
- if pfinal[1] == 'Sucesso': pfeitos += 1
- print(f'Total of pieces made:{total}\nProduct losses:{total-pfeitos} Time:{tempo}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement