Sunday 20 December 2015

Python: multiprocessing: log_to_stderr(): debugging


By using log_to_stderr(), you can enable logging, this feature us helpful while debugging a multiprocess application.
from multiprocessing import Process
import multiprocessing
import logging

def print_data():
    name = multiprocessing.current_process().name
    id = multiprocessing.current_process().pid
    print(name, id)
    print("Processing finished")

if __name__=="__main__":
    multiprocessing.log_to_stderr(logging.DEBUG)
    proc1 = Process(name='process1', target=print_data)

    proc1.start()
    proc1.join()

    print("Is proc1 alive ",proc1.is_alive())


    print("Finished")


Output
process1 31904
Processing finished
[INFO/process1] child process calling self.run()
[INFO/process1] process shutting down
Is proc1 alive  False
Finished
[DEBUG/process1] running all "atexit" finalizers with priority >= 0
[DEBUG/process1] running the remaining "atexit" finalizers
[INFO/process1] process exiting with exitcode 0
[INFO/MainProcess] process shutting down
[DEBUG/MainProcess] running all "atexit" finalizers with priority >= 0
[DEBUG/MainProcess] running the remaining "atexit" finalizers



Previous                                                 Next                                                 Home

No comments:

Post a Comment