Skip to content

Commit c9fbc10

Browse files
author
georg.brandl
committed
#3993: fix old-style print statements.
git-svn-id: http://svn.python.org/projects/python/branches/py3k@66680 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 2b8cef4 commit c9fbc10

1 file changed

Lines changed: 43 additions & 43 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
Introduction
9-
----------------------
9+
------------
1010

1111
:mod:`multiprocessing` is a package that supports spawning processes using an
1212
API similar to the :mod:`threading` module. The :mod:`multiprocessing` package
@@ -28,7 +28,7 @@ multiprocess program is ::
2828
from multiprocessing import Process
2929

3030
def f(name):
31-
print 'hello', name
31+
print('hello', name)
3232

3333
if __name__ == '__main__':
3434
p = Process(target=f, args=('bob',))
@@ -62,7 +62,7 @@ processes:
6262
q = Queue()
6363
p = Process(target=f, args=(q,))
6464
p.start()
65-
print q.get() # prints "[42, None, 'hello']"
65+
print(q.get()) # prints "[42, None, 'hello']"
6666
p.join()
6767

6868
Queues are thread and process safe.
@@ -82,7 +82,7 @@ processes:
8282
parent_conn, child_conn = Pipe()
8383
p = Process(target=f, args=(child_conn,))
8484
p.start()
85-
print parent_conn.recv() # prints "[42, None, 'hello']"
85+
print(parent_conn.recv()) # prints "[42, None, 'hello']"
8686
p.join()
8787

8888
The two connection objects returned by :func:`Pipe` represent the two ends of
@@ -105,7 +105,7 @@ that only one process prints to standard output at a time::
105105

106106
def f(l, i):
107107
l.acquire()
108-
print 'hello world', i
108+
print('hello world', i)
109109
l.release()
110110

111111
if __name__ == '__main__':
@@ -148,8 +148,8 @@ However, if you really do need to use some shared data then
148148
p.start()
149149
p.join()
150150

151-
print num.value
152-
print arr[:]
151+
print(num.value)
152+
print(arr[:])
153153

154154
will print ::
155155

@@ -195,8 +195,8 @@ However, if you really do need to use some shared data then
195195
p.start()
196196
p.join()
197197

198-
print d
199-
print l
198+
print(d)
199+
print(l)
200200

201201
will print ::
202202

@@ -224,10 +224,10 @@ For example::
224224
return x*x
225225

226226
if __name__ == '__main__':
227-
pool = Pool(processes=4) # start 4 worker processes
228-
result = pool.applyAsync(f, [10]) # evaluate "f(10)" asynchronously
229-
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
230-
print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]"
227+
pool = Pool(processes=4) # start 4 worker processes
228+
result = pool.applyAsync(f, [10]) # evaluate "f(10)" asynchronously
229+
print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow
230+
print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]"
231231

232232

233233
Reference
@@ -371,13 +371,13 @@ The :mod:`multiprocessing` package mostly replicates the API of the
371371

372372
>>> import processing, time, signal
373373
>>> p = processing.Process(target=time.sleep, args=(1000,))
374-
>>> print p, p.is_alive()
374+
>>> print(p, p.is_alive())
375375
<Process(Process-1, initial)> False
376376
>>> p.start()
377-
>>> print p, p.is_alive()
377+
>>> print(p, p.is_alive())
378378
<Process(Process-1, started)> True
379379
>>> p.terminate()
380-
>>> print p, p.is_alive()
380+
>>> print(p, p.is_alive())
381381
<Process(Process-1, stopped[SIGTERM])> False
382382
>>> p.exitcode == -signal.SIGTERM
383383
True
@@ -612,7 +612,7 @@ Miscellaneous
612612
from multiprocessing import Process, freeze_support
613613

614614
def f():
615-
print 'hello world!'
615+
print('hello world!')
616616

617617
if __name__ == '__main__':
618618
freeze_support()
@@ -1011,13 +1011,13 @@ process::
10111011
p.start()
10121012
p.join()
10131013

1014-
print n.value
1015-
print x.value
1016-
print s.value
1017-
print [(a.x, a.y) for a in A]
1014+
print(n.value)
1015+
print(x.value)
1016+
print(s.value)
1017+
print([(a.x, a.y) for a in A])
10181018

10191019

1020-
.. highlightlang:: none
1020+
.. highlight:: none
10211021

10221022
The results printed are ::
10231023

@@ -1026,7 +1026,7 @@ The results printed are ::
10261026
HELLO WORLD
10271027
[(3.515625, 39.0625), (33.0625, 4.0), (5.640625, 90.25)]
10281028

1029-
.. highlightlang:: python
1029+
.. highlight:: python
10301030

10311031

10321032
.. _multiprocessing-managers:
@@ -1212,7 +1212,7 @@ However, when using a proxy for a namespace object, an attribute beginning with
12121212
>>> Global.x = 10
12131213
>>> Global.y = 'hello'
12141214
>>> Global._z = 12.3 # this is an attribute of the proxy
1215-
>>> print Global
1215+
>>> print(Global)
12161216
Namespace(x=10, y='hello')
12171217

12181218

@@ -1240,8 +1240,8 @@ callables with the manager class. For example::
12401240
manager = MyManager()
12411241
manager.start()
12421242
maths = manager.Maths()
1243-
print maths.add(4, 3) # prints 7
1244-
print maths.mul(7, 8) # prints 56
1243+
print(maths.add(4, 3)) # prints 7
1244+
print(maths.mul(7, 8)) # prints 56
12451245

12461246

12471247
Using a remote manager
@@ -1300,9 +1300,9 @@ referent can::
13001300
>>> from multiprocessing import Manager
13011301
>>> manager = Manager()
13021302
>>> l = manager.list([i*i for i in range(10)])
1303-
>>> print l
1303+
>>> print(l)
13041304
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
1305-
>>> print repr(l)
1305+
>>> print(repr(l))
13061306
<ListProxy object, typeid 'list' at 0xb799974c>
13071307
>>> l[4]
13081308
16
@@ -1321,10 +1321,10 @@ itself. This means, for example, that one shared object can contain a second::
13211321
>>> a = manager.list()
13221322
>>> b = manager.list()
13231323
>>> a.append(b) # referent of a now contains referent of b
1324-
>>> print a, b
1324+
>>> print(a, b)
13251325
[[]] []
13261326
>>> b.append('hello')
1327-
>>> print a, b
1327+
>>> print(a, b)
13281328
[['hello']] ['hello']
13291329

13301330
.. note::
@@ -1529,18 +1529,18 @@ The following example demonstrates the use of a pool::
15291529
pool = Pool(processes=4) # start 4 worker processes
15301530

15311531
result = pool.applyAsync(f, (10,)) # evaluate "f(10)" asynchronously
1532-
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
1532+
print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow
15331533

1534-
print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]"
1534+
print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]"
15351535

15361536
it = pool.imap(f, range(10))
1537-
print it.next() # prints "0"
1538-
print it.next() # prints "1"
1539-
print it.next(timeout=1) # prints "4" unless your computer is *very* slow
1537+
print(next(it)) # prints "0"
1538+
print(next(it)) # prints "1"
1539+
print(it.next(timeout=1)) # prints "4" unless your computer is *very* slow
15401540

15411541
import time
15421542
result = pool.applyAsync(time.sleep, (10,))
1543-
print result.get(timeout=1) # raises TimeoutError
1543+
print(result.get(timeout=1)) # raises TimeoutError
15441544

15451545

15461546
.. _multiprocessing-listeners-clients:
@@ -1670,7 +1670,7 @@ the client::
16701670
listener = Listener(address, authkey='secret password')
16711671

16721672
conn = listener.accept()
1673-
print 'connection accepted from', listener.last_accepted
1673+
print('connection accepted from', listener.last_accepted)
16741674

16751675
conn.send([2.25, None, 'junk', float])
16761676

@@ -1690,13 +1690,13 @@ server::
16901690
address = ('localhost', 6000)
16911691
conn = Client(address, authkey='secret password')
16921692

1693-
print conn.recv() # => [2.25, None, 'junk', float]
1693+
print(conn.recv()) # => [2.25, None, 'junk', float]
16941694

1695-
print conn.recv_bytes() # => 'hello'
1695+
print(conn.recv_bytes()) # => 'hello'
16961696

16971697
arr = array('i', [0, 0, 0, 0, 0])
1698-
print conn.recv_bytes_into(arr) # => 8
1699-
print arr # => array('i', [42, 1729, 0, 0, 0])
1698+
print(conn.recv_bytes_into(arr)) # => 8
1699+
print(arr) # => array('i', [42, 1729, 0, 0, 0])
17001700

17011701
conn.close()
17021702

@@ -1957,7 +1957,7 @@ Safe importing of main module
19571957
from multiprocessing import Process
19581958

19591959
def foo():
1960-
print 'hello'
1960+
print('hello')
19611961

19621962
p = Process(target=foo)
19631963
p.start()
@@ -1968,7 +1968,7 @@ Safe importing of main module
19681968
from multiprocessing import Process, freeze_support
19691969

19701970
def foo():
1971-
print 'hello'
1971+
print('hello')
19721972

19731973
if __name__ == '__main__':
19741974
freeze_support()

0 commit comments

Comments
 (0)