Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

python - Running multiple functions concurrently

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...