[New-bugs-announce] [issue6417] multiprocessing Process examples: print and getppid

Michael Newman report at bugs.python.org
Sat Jul 4 16:58:45 CEST 2009


New submission from Michael Newman <michael.b.newman at gmail.com>:

The "16.6.1.1. The Process class" section of the multiprocessing
documentation:
http://docs.python.org/dev/py3k/library/multiprocessing.html
has errors in both examples.

The first example needs the indentation fixed on the "from" and "if"
lines (remove the leading spaces).

The second example has two issues: print syntax needs be updated from
2.0 to 3.0 syntax. Also, getppid is not available on win32 platforms.
Below is a corrected example, which I tested successfully on on win32
and linux:

# Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32
C:\>c:\Python31\python.exe Process_with_more_info.py
main line
module name: __main__
parent process: None
process id: 3216
function f
module name: __main__
parent process: 3216
process id: 3692
hello bob

# Python 3.0.1 (r301:69556, Jun  6 2009, 21:34:43) [GCC 4.3.2] on linux2
mike at www:~/files$ python3.0 Process_with_more_info.py
main line
module name: __main__
parent process: 19853
process id: 22544
function f
module name: __main__
parent process: 22544
process id: 22545
hello bob

# Start of corrected example:

from multiprocessing import Process, current_process
from sys import platform
import os

def info(title):
    print(title)
    print('module name:', __name__)
    if platform == '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()

# End of corrected example.

I also saw this online:
"os.getppid on Windows"
http://d.hatena.ne.jp/chrono-meter/20090325/p1
But the license of the code is not clear, and it would make the example
too confusing to insert in.

Another reference:
"Multiprocessing docs are not 3.0-ready"
http://bugs.python.org/issue3256
Looks like some print statements fixed back then, but not sure why the
examples mentioned here were not fixed.

----------
assignee: georg.brandl
components: Documentation
messages: 90118
nosy: georg.brandl, mnewman
severity: normal
status: open
title: multiprocessing Process examples: print and getppid
versions: Python 3.1

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


More information about the New-bugs-announce mailing list