Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58ea9fe

Browse files
committed
Merged revisions 65864 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r65864 | jesse.noller | 2008-08-19 14:06:19 -0500 (Tue, 19 Aug 2008) | 2 lines issue3352: clean up the multiprocessing API to remove many get_/set_ methods and convert them to properties. Update the docs and the examples included. ........
1 parent be2c2b2 commit 58ea9fe

15 files changed

Lines changed: 86 additions & 92 deletions

Doc/includes/mp_distributing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import subprocess
1818
import logging
1919
import itertools
20-
import Queue
20+
import queue
2121

2222
try:
23-
import cPickle as pickle
23+
import pickle as pickle
2424
except ImportError:
2525
import pickle
2626

@@ -152,7 +152,7 @@ def _help_stuff_finish(inqueue, task_handler, size):
152152

153153
def LocalProcess(**kwds):
154154
p = Process(**kwds)
155-
p.set_name('localhost/' + p.get_name())
155+
p.set_name('localhost/' + p.name)
156156
return p
157157

158158
class Cluster(managers.SyncManager):
@@ -210,7 +210,7 @@ def shutdown(self):
210210
self._base_shutdown()
211211

212212
def Process(self, group=None, target=None, name=None, args=(), kwargs={}):
213-
slot = self._slot_iterator.next()
213+
slot = next(self._slot_iterator)
214214
return slot.Process(
215215
group=group, target=target, name=name, args=args, kwargs=kwargs
216216
)
@@ -231,7 +231,7 @@ def __iter__(self):
231231
# Queue subclass used by distributed pool
232232
#
233233

234-
class SettableQueue(Queue.Queue):
234+
class SettableQueue(queue.Queue):
235235
def empty(self):
236236
return not self.queue
237237
def full(self):
@@ -243,7 +243,7 @@ def set_contents(self, contents):
243243
try:
244244
self.queue.clear()
245245
self.queue.extend(contents)
246-
self.not_empty.notify_all()
246+
self.not_empty.notifyAll()
247247
finally:
248248
self.not_empty.release()
249249

Doc/includes/mp_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def calculate(func, args):
1515
result = func(*args)
1616
return '%s says that %s%s = %s' % (
17-
multiprocessing.current_process().get_name(),
17+
multiprocessing.current_process().name,
1818
func.__name__, args, result
1919
)
2020

Doc/includes/mp_synchronize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_sharedvalues():
224224
p.start()
225225
p.join()
226226

227-
assert p.get_exitcode() == 0
227+
assert p.exitcode == 0
228228

229229

230230
####

Doc/includes/mp_webserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
def note(format, *args):
24-
sys.stderr.write('[%s]\t%s\n' % (current_process().get_name(),format%args))
24+
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
2525

2626

2727
class RequestHandler(SimpleHTTPRequestHandler):

Doc/includes/mp_workers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def worker(input, output):
2929
def calculate(func, args):
3030
result = func(*args)
3131
return '%s says that %s%s = %s' % \
32-
(current_process().get_name(), func.__name__, args, result)
32+
(current_process().name, func.__name__, args, result)
3333

3434
#
3535
# Functions referenced by tasks

Doc/library/multiprocessing.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ The :mod:`multiprocessing` package mostly replicates the API of the
290290
A process cannot join itself because this would cause a deadlock. It is
291291
an error to attempt to join a process before it has been started.
292292

293-
.. method:: get_name()
293+
.. attribute:: Process.name
294294

295295
Return the process's name.
296296

297-
.. method:: set_name(name)
297+
.. attribute:: Process.name = name
298298

299299
Set the process's name.
300300

@@ -309,11 +309,11 @@ The :mod:`multiprocessing` package mostly replicates the API of the
309309
Roughly, a process object is alive from the moment the :meth:`start`
310310
method returns until the child process terminates.
311311

312-
.. method:: is_daemon()
312+
.. attribute:: Process.daemon
313313

314-
Return the process's daemon flag.
314+
Return the process's daemon flag., this is a boolean.
315315

316-
.. method:: set_daemon(daemonic)
316+
.. attribute:: Process.daemon = daemonic
317317

318318
Set the process's daemon flag to the Boolean value *daemonic*. This must
319319
be called before :meth:`start` is called.
@@ -329,18 +329,18 @@ The :mod:`multiprocessing` package mostly replicates the API of the
329329

330330
In addition process objects also support the following methods:
331331

332-
.. method:: get_pid()
332+
.. attribute:: Process.pid
333333

334334
Return the process ID. Before the process is spawned, this will be
335335
``None``.
336336

337-
.. method:: get_exit_code()
337+
.. attribute:: Process.exitcode
338338

339339
Return the child's exit code. This will be ``None`` if the process has
340340
not yet terminated. A negative value *-N* indicates that the child was
341341
terminated by signal *N*.
342342

343-
.. method:: get_auth_key()
343+
.. attribute:: Process.authkey
344344

345345
Return the process's authentication key (a byte string).
346346

@@ -349,11 +349,11 @@ The :mod:`multiprocessing` package mostly replicates the API of the
349349

350350
When a :class:`Process` object is created, it will inherit the
351351
authentication key of its parent process, although this may be changed
352-
using :meth:`set_auth_key` below.
352+
using :attr:`Process.authkey` below.
353353

354354
See :ref:`multiprocessing-auth-keys`.
355355

356-
.. method:: set_auth_key(authkey)
356+
.. attribute:: Process.authkey = authkey
357357

358358
Set the process's authentication key which must be a byte string.
359359

Lib/multiprocessing/dummy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def start(self):
4747
self._parent._children[self] = None
4848
threading.Thread.start(self)
4949

50-
def get_exitcode(self):
50+
@property
51+
def exitcode(self):
5152
if self._start_called and not self.is_alive():
5253
return 0
5354
else:

Lib/multiprocessing/forking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def get_preparation_data(name):
315315
sys_argv=sys.argv,
316316
log_to_stderr=_log_to_stderr,
317317
orig_dir=process.ORIGINAL_DIR,
318-
authkey=process.current_process().get_authkey(),
318+
authkey=process.current_process().authkey,
319319
)
320320

321321
if _logger is not None:
@@ -363,7 +363,7 @@ def prepare(data):
363363
old_main_modules.append(sys.modules['__main__'])
364364

365365
if 'name' in data:
366-
process.current_process().set_name(data['name'])
366+
process.current_process().name = data['name']
367367

368368
if 'authkey' in data:
369369
process.current_process()._authkey = data['authkey']

Lib/multiprocessing/managers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class BaseManager(object):
450450

451451
def __init__(self, address=None, authkey=None, serializer='pickle'):
452452
if authkey is None:
453-
authkey = current_process().get_authkey()
453+
authkey = current_process().authkey
454454
self._address = address # XXX not final address if eg ('', 0)
455455
self._authkey = AuthenticationString(authkey)
456456
self._state = State()
@@ -495,7 +495,7 @@ def start(self):
495495
self._serializer, writer),
496496
)
497497
ident = ':'.join(str(i) for i in self._process._identity)
498-
self._process.set_name(type(self).__name__ + '-' + ident)
498+
self._process.name = type(self).__name__ + '-' + ident
499499
self._process.start()
500500

501501
# get address of server
@@ -696,7 +696,7 @@ def __init__(self, token, serializer, manager=None,
696696
elif self._manager is not None:
697697
self._authkey = self._manager._authkey
698698
else:
699-
self._authkey = current_process().get_authkey()
699+
self._authkey = current_process().authkey
700700

701701
if incref:
702702
self._incref()
@@ -705,7 +705,7 @@ def __init__(self, token, serializer, manager=None,
705705

706706
def _connect(self):
707707
util.debug('making connection to manager')
708-
name = current_process().get_name()
708+
name = current_process().name
709709
if threading.current_thread().name != 'MainThread':
710710
name += '|' + threading.current_thread().name
711711
conn = self._Client(self._token.address, authkey=self._authkey)
@@ -886,7 +886,7 @@ def AutoProxy(token, serializer, manager=None, authkey=None,
886886
if authkey is None and manager is not None:
887887
authkey = manager._authkey
888888
if authkey is None:
889-
authkey = current_process().get_authkey()
889+
authkey = current_process().authkey
890890

891891
ProxyType = MakeProxyType('AutoProxy[%s]' % token.typeid, exposed)
892892
proxy = ProxyType(token, serializer, manager=manager, authkey=authkey,

Lib/multiprocessing/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, processes=None, initializer=None, initargs=()):
9999
args=(self._inqueue, self._outqueue, initializer, initargs)
100100
)
101101
self._pool.append(w)
102-
w.name = w.get_name().replace('Process', 'PoolWorker')
102+
w.name = w.name.replace('Process', 'PoolWorker')
103103
w.daemon = True
104104
w.start()
105105

0 commit comments

Comments
 (0)