The goal of my code is to run both westernEurope.infection()
and easternEurope.infection()
at the same time. The thing is, I also want to be able to output the sum of the self.cases
from both of the objects. I have never used multiprocessing or threading before, so was wondering which one is better to use in this case, as well as guidance on how the code should be presented
class Region:
def __init__(self, name, population, cases, deaths):
self.name = name
self.population = population
self.cases = cases
self.deaths = deaths
def infection(self):
while self.population > self.cases:
self.cases = self.cases + random.randint(0,8)
westernEurope = Region("Western Europe", 1000, 0, 0)
westernEurope.infection()
easternEurope = Region("Eastern Europe", 1000, 0, 0)
easternEurope.infection()
#totalCases = will print the sum of self.cases of both easternEurope and westernEurope
question from:
https://stackoverflow.com/questions/65872436/running-multiple-functions-concurrently 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…