[issue6417] multiprocessing Process examples: print and getppid

Michael Newman report at bugs.python.org
Sat Jul 4 17:48:46 CEST 2009


Michael Newman <michael.b.newman at gmail.com> added the comment:

# Revised example that is more platform neutral (avoids sys.platform):

from multiprocessing import Process, current_process
import os

def info(title):
    print(title)
    print('module name:', __name__)
    if not hasattr(os, 'getppid'):  # win32
      print('parent process:', current_process()._parent_pid)
    else:
      print('parent process:', os.getppid())
    print('process id:', os.getpid())

def f(name):
    info('function f')
    print('hello', name)

if __name__ == '__main__':
    info('main line')
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6417>
_______________________________________


More information about the Python-bugs-list mailing list