test
test

Reputation: 5

python parallel processing and select best code

i have code like this .


import multiprocessing 
import time 

class Process(multiprocessing.Process): 
    def __init__(self, id): 
        super(Process, self).__init__() 
        self.id = id
                 
    def run(self): 
        time.sleep(1) 

        print("run "+"."+str(self.id))

can i build n process that run same time and when one of them finish stopping all other processes?

Upvotes: 0

Views: 96

Answers (1)

user3224611
user3224611

Reputation: 84

there are a couple of ways. basically, you need some of sync. once the condition reached, the rest of the processes calls terminate function

for details, see this:

Terminate a Python multiprocessing program once a one of its workers meets a certain condition

Upvotes: 0

Related Questions