Sunday 20 December 2015

Python: Get active children of current process


‘multiprocessing.active_children()’ method returns number of active children for current process.
import multiprocessing
import time

def process_data():
    print("Started processing data")
    time.sleep(3)
    print("Finished processing")

if(__name__=="__main__"):
    process1 = multiprocessing.Process(target=process_data)
    process2 = multiprocessing.Process(target=process_data)

    process1.start()
    process2.start()

    list = multiprocessing.active_childern()

    for proc in list :
        print(proc)



Previous                                                 Next                                                 Home

No comments:

Post a Comment