Commit 6c376744 authored by Jesse Noller's avatar Jesse Noller

issue5738: The distribution example was confusing, and out of date. It's too...

issue5738: The distribution example was confusing, and out of date. It's too large to include inline in the docs as well. It belongs in an addons module outside the stdlib. Removing.
parent c4920e86
This diff is collapsed.
...@@ -2230,10 +2230,3 @@ Some simple benchmarks comparing :mod:`multiprocessing` with :mod:`threading`: ...@@ -2230,10 +2230,3 @@ Some simple benchmarks comparing :mod:`multiprocessing` with :mod:`threading`:
.. literalinclude:: ../includes/mp_benchmarks.py .. literalinclude:: ../includes/mp_benchmarks.py
An example/demo of how to use the :class:`managers.SyncManager`, :class:`Process`
and others to build a system which can distribute processes and work via a
distributed queue to a "cluster" of machines on a network, accessible via SSH.
You will need to have private key authentication for all hosts configured for
this to work.
.. literalinclude:: ../includes/mp_distributing.py
...@@ -47,6 +47,8 @@ class Queue(object): ...@@ -47,6 +47,8 @@ class Queue(object):
if sys.platform != 'win32': if sys.platform != 'win32':
register_after_fork(self, Queue._after_fork) register_after_fork(self, Queue._after_fork)
self.getv = 0
def __getstate__(self): def __getstate__(self):
assert_spawning(self) assert_spawning(self)
return (self._maxsize, self._reader, self._writer, return (self._maxsize, self._reader, self._writer,
...@@ -71,6 +73,8 @@ class Queue(object): ...@@ -71,6 +73,8 @@ class Queue(object):
self._poll = self._reader.poll self._poll = self._reader.poll
def put(self, obj, block=True, timeout=None): def put(self, obj, block=True, timeout=None):
if not isinstance(obj, list):
debug('put: %s', obj)
assert not self._closed assert not self._closed
if not self._sem.acquire(block, timeout): if not self._sem.acquire(block, timeout):
raise Full raise Full
...@@ -85,11 +89,15 @@ class Queue(object): ...@@ -85,11 +89,15 @@ class Queue(object):
self._notempty.release() self._notempty.release()
def get(self, block=True, timeout=None): def get(self, block=True, timeout=None):
self.getv += 1
debug('self.getv: %s', self.getv)
if block and timeout is None: if block and timeout is None:
self._rlock.acquire() self._rlock.acquire()
try: try:
res = self._recv() res = self._recv()
self._sem.release() self._sem.release()
if not isinstance(res, list):
debug('get: %s', res)
return res return res
finally: finally:
self._rlock.release() self._rlock.release()
...@@ -104,6 +112,8 @@ class Queue(object): ...@@ -104,6 +112,8 @@ class Queue(object):
raise Empty raise Empty
res = self._recv() res = self._recv()
self._sem.release() self._sem.release()
if not isinstance(res, list):
debug('get: %s', res)
return res return res
finally: finally:
self._rlock.release() self._rlock.release()
...@@ -229,16 +239,22 @@ class Queue(object): ...@@ -229,16 +239,22 @@ class Queue(object):
try: try:
while 1: while 1:
obj = bpopleft() obj = bpopleft()
if not isinstance(obj, list):
debug('feeder thread got: %s', obj)
if obj is sentinel: if obj is sentinel:
debug('feeder thread got sentinel -- exiting') debug('feeder thread got sentinel -- exiting')
close() close()
return return
if wacquire is None: if wacquire is None:
if not isinstance(obj, list):
debug('sending to pipe: %s', obj)
send(obj) send(obj)
else: else:
wacquire() debug('waiting on wacquire')
wacquire(timeout=30)
try: try:
if not isinstance(obj, list):
debug('sending to pipe: %s', obj)
send(obj) send(obj)
finally: finally:
wrelease() wrelease()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment