0

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?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
test
  • 5
  • 3

1 Answers1

0

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

user3224611
  • 84
  • 1
  • 7