Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue6417] multiprocessing Process examples: print and getppid

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 4, 2009, 7:58 AM

Post #1 of 4 (169 views)
Permalink
[issue6417] multiprocessing Process examples: print and getppid

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>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2009, 8:22 AM

Post #2 of 4 (151 views)
Permalink
[issue6417] multiprocessing Process examples: print and getppid [In reply to]

Changes by Benjamin Peterson <benjamin[at]python.org>:


----------
assignee: georg.brandl -> jnoller
nosy: +jnoller

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue6417>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2009, 8:48 AM

Post #3 of 4 (151 views)
Permalink
[issue6417] multiprocessing Process examples: print and getppid [In reply to]

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>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2009, 4:46 PM

Post #4 of 4 (143 views)
Permalink
[issue6417] multiprocessing Process examples: print and getppid [In reply to]

Changes by Jesse Noller <jnoller[at]gmail.com>:


----------
priority: -> normal

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue6417>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.