Skip to content

Commit

Permalink
documentation and examples changed to reflect async -> asyncproxy ren…
Browse files Browse the repository at this point in the history
…ame.
  • Loading branch information
irmen committed Nov 9, 2017
1 parent c5bc8b1 commit 2684b1a
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/source/api/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ symbol in :mod:`Pyro4` referenced location
.. py:class:: Future :class:`Pyro4.futures.Future`
.. py:function:: callback :func:`Pyro4.core.callback`
.. py:function:: batch :func:`Pyro4.core.batch`
.. py:function:: async :func:`Pyro4.core.async`
.. py:function:: asyncproxy :func:`Pyro4.core.asyncproxy`
.. py:function:: locateNS :func:`Pyro4.naming.locateNS`
.. py:function:: resolve :func:`Pyro4.naming.resolve`
.. py:function:: expose :func:`Pyro4.core.expose` (decorator ``@expose``)
Expand Down
6 changes: 4 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Change Log

**Pyro 4.64**

- **incompatible API change** for python 3.7 compatibility: renamed core.async to core.asyncproxy and the async keyword to asynchronous.
This had to be done because `async` (and `await`) are keywords in Python 3.7 and using them otherwise would result in a SyntaxError.
- **incompatible API change** for python 3.7 compatibility: renamed ``core.async`` to ``core.asyncproxy``
and the ``async`` keyword argument in some methods to ``asynchronous``.
This had to be done because ``async`` (and ``await``) are now parsed as keywords in Python 3.7 and using them otherwise will result
in a SyntaxError when loading the module.
- dropped support for Python 3.3 (which has reached end-of-life status). Supported Python versions are now 2.7, and 3.4 or newer.


Expand Down
16 changes: 8 additions & 8 deletions docs/source/clientcode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ How it works:
You create a batch proxy using this: ``batch = Pyro4.batch(proxy)`` or this (equivalent): ``batch = proxy._pyroBatch()``.
The signature of the batch proxy call is as follows:

.. py:method:: batchproxy.__call__([oneway=False, async=False])
.. py:method:: batchproxy.__call__([oneway=False, asynchronous=False])
Invoke the batch and when done, returns a generator that produces the results of every call, in order.
If ``oneway==True``, perform the whole batch as one-way calls, and return ``None`` immediately.
If ``async==True``, perform the batch asynchronously, and return an asynchronous call result object immediately.
If ``asynchronous==True``, perform the batch asynchronously, and return an asynchronous call result object immediately.

**Simple example**::

Expand All @@ -383,8 +383,8 @@ The signature of the batch proxy call is as follows:
The result value of an asynchronous batch call is a special object. See :ref:`async-calls` for more details about it.
This is some simple code doing an asynchronous batch::

results = batch(async=True)
# do some stuff... until you're ready and require the results of the async batch:
results = batch(asynchronous=True)
# do some stuff... until you're ready and require the results of the asynchronous batch:
for result in results.value:
print(result) # process the results

Expand Down Expand Up @@ -452,7 +452,7 @@ Have a look at the :file:`stockquotes` tutorial example, or the :file:`filetrans



.. index:: async call, future, call chaining
.. index:: asynchronous call, future, call chaining

.. _async-calls:

Expand All @@ -467,8 +467,8 @@ meantime, the code doesn't block at all and can process the results immediately.
It is possible to define one or more callables (the "call chain") that should be invoked
automatically by Pyro as soon as the result value becomes available.

You set a proxy in async mode using this: ``Pyro4.async(proxy)`` or (equivalent): ``proxy._pyroAsync()``.
Every remote method call you make on the async proxy, returns a
You set a proxy in asynchronous mode using this: ``Pyro4.asyncproxy(proxy)`` or (equivalent): ``proxy._pyroAsync()``.
Every remote method call you make on the asynchronous proxy, returns a
:py:class:`Pyro4.futures.FutureResult` object immediately.
This object means 'the result of this will be available at some moment in the future' and has the following interface:

Expand Down Expand Up @@ -520,7 +520,7 @@ See the :file:`async` example for more details and example code for call chains.

Async calls for normal callables (not only for Pyro proxies)
------------------------------------------------------------
The async proxy discussed above is only available when you are dealing with Pyro proxies.
The asynchrnous proxy discussed above is only available when you are dealing with Pyro proxies.
It provides a convenient syntax to call the methods on the proxy asynchronously.
For normal Python code it is sometimes useful to have a similar mechanism as well.
Pyro provides this too, see :ref:`future-functions` for more information.
Expand Down
8 changes: 4 additions & 4 deletions docs/source/tipstricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ To find out the protocol version that your client code is using, you can use thi



.. index:: async, futures
.. index:: asynchronous, futures

.. _future-functions:

Asynchronous ('future') normal function calls
=============================================
Pyro provides an async proxy to call remote methods asynchronously, see :ref:`async-calls`.
Pyro provides an asynchronous proxy to call remote methods asynchronously, see :ref:`async-calls`.
For normal Python code, Python provides a similar mechanism in the form of the
:py:class:`Pyro4.futures.Future` class (also available as ``Pyro4.Future``).
With a syntax that is slightly different from normal method calls,
it provides the same asynchronous function calls as the async proxy has.
it provides the same asynchronous function calls as the asynchronous proxy has.
Note that Python itself has a similar thing in the standard library since version 3.2, see
http://docs.python.org/3/library/concurrent.futures.html#future-objects . However Pyro's Future
object is available on older Python versions too. It works slightly differently and perhaps
Expand All @@ -230,7 +230,7 @@ and receive its results somewhere in the future::
summation = result.value

Actually calling the `Future` object returns control immediately and results in a :py:class:`Pyro4.futures.FutureResult`
object. This is the exact same class as with the async proxy. The most important attributes are ``value``, ``ready``
object. This is the exact same class as with the asynchrnous proxy. The most important attributes are ``value``, ``ready``
and the ``wait`` method. See :ref:`async-calls` for more details.

You can also chain multiple calls, so that the whole call chain is executed sequentially in the background.
Expand Down
6 changes: 3 additions & 3 deletions examples/async/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ This is an example that shows the asynchronous method call support.
The server has a single method that has an artificial delay of three seconds
before it returns the result of the computation.

The client shows how you might use Pyro's async feature to run the remote
The client shows how you might use Pyro's asynchronous feature to run the remote
method call in the background and deal with the results later (when they
are available).

client_batch.py shows how to do async batched calls.
client_batch.py shows how to do asynchronous batched calls.
Notice how this is different from oneway batched calls because
we will get results this time (just somewhere in the future).
Oneway calls never return a result.

client_callchain.py shows the 'call chain' feature, where you can chain
one or more asynchronous function calls to be performed as soon as the
async call result became available. You can chain normal functions but
asynchronous call result became available. You can chain normal functions but
also more pyro calls. The result of the previous call is passed
to the next call as argument.
8 changes: 4 additions & 4 deletions examples/async/client_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def asyncFunction(values):
batch.divide(99, 9)
batch.divide(555, 2)
print("getting results...")
asyncresults = batch(async=True) # returns immediately
asyncresults = batch(asynchronous=True) # returns immediately
print("result value available?", asyncresults.ready) # prints False because the server is still 'busy'
print("client can do other stuff here.")
time.sleep(2)
Expand All @@ -41,7 +41,7 @@ def asyncFunction(values):
batch.divide(100, 5)
batch.divide(99, 9)
batch.divide(555, 2)
asyncresults = batch(async=True) # returns immediately
asyncresults = batch(asynchronous=True) # returns immediately
asyncresults.then(asyncFunction) \
.then(asyncFunction) \
.then(asyncFunction)
Expand All @@ -52,7 +52,7 @@ def asyncFunction(values):
batch = Pyro4.batch(proxy)
batch.divide(1, 1) # first call is ok
batch.divide(100, 0) # second call will trigger a zero division error, 100//0
asyncresults = batch(async=True) # returns immediately
asyncresults = batch(asynchronous=True) # returns immediately
print("getting result values...")
try:
value = asyncresults.value
Expand All @@ -65,7 +65,7 @@ def asyncFunction(values):
batch.divide(100, 5)
batch.divide(99, 9)
batch.divide(555, 2)
asyncresults = batch(async=True) # returns immediately
asyncresults = batch(asynchronous=True) # returns immediately
print("checking if ready within 2 seconds...")
ready = asyncresults.wait(2) # wait for ready within 2 seconds but the server takes 3
print("status after wait=", ready) # should print False
Expand Down
8 changes: 4 additions & 4 deletions examples/batchedcalls/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@
print("total time taken {0:.2f} seconds ({1:.0f} calls/sec)".format(duration, NUMBER_OF_LOOPS * 2.0 / duration // 100 * 100))
print("oneway batched calls were {0:.1f} times faster than normal remote calls".format(duration_normal / duration))

# Batches can be executed async as well
print("\nBatched remote calls, async...")
# Batches can be executed asynchronous as well
print("\nBatched remote calls, asynchronous...")
batch = Pyro4.batch(p) # get a batched call proxy for 'p'
batch.printmessage("beginning batch #3")
batch.multiply(7, 6) # queue a call, note that it returns 'None' immediately
batch.add(10, 20) # queue a call, note that it returns 'None' immediately
batch.delay(2) # queue a delay, but this doesn't matter with async
batch.delay(2) # queue a delay, but this doesn't matter with asynchronous proxy
batch.printmessage("end of batch #3")
print("executing the batch... (should return immediately because async)")
asyncresult = batch(async=True) # execute the batch, async (return immediately)
asyncresult = batch(asynchronous=True) # execute the batch, asynchronously (return immediately)
print("processing the results...(should wait until async results become available)")
results = list(asyncresult.value)
print("results=", results)
Expand Down
4 changes: 2 additions & 2 deletions examples/callcontext/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def _pyroResponseAnnotations(self, annotations, msgtype):
proxy.oneway("hello-ONEWAY-1")
print("Sending another oneway message... (should not print a response at all)")
proxy.oneway("hello-ONEWAY-2")
# async
print("Async proxy message...")
# asynchronous
print("Asynchronous proxy message...")
proxy._pyroAsync()
result = proxy.echo("hello-ASYNC")
_ = result.value
Expand Down
6 changes: 3 additions & 3 deletions examples/distributed-computing2/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def count(self, lines):
all_counters = ns.list(prefix="example.dc.wordcount.")
counters = [Pyro4.Proxy(uri) for uri in all_counters.values()]
for c in counters:
c._pyroAsync() # set proxy in async mode
c._pyroAsync() # set proxy in asynchronous mode
roundrobin_counters = cycle(counters)

# chop the text into chunks that can be distributed across the workers
# uses async proxy so that we can hand off everything in parallel
# uses asynchronous proxy so that we can hand off everything in parallel
# counter is selected in a round-robin fashion from list of all available counters
# (This is a brain dead way because it doesn't scale - all the async calls are hogging
# (This is a brain dead way because it doesn't scale - all the asynchronous calls are hogging
# the worker threads in the server. That's why we've increased that a lot at the start
# of this file, just for the sake of this example!)
async_results = []
Expand Down
2 changes: 1 addition & 1 deletion examples/distributed-mandelbrot/client_asciizoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def screen(self, start, width):
server = servers[i % len(servers)]
server.calc_line(start, self.res_x, i*di, dr, i)
for batch in servers:
batch(async=True).then(self.batch_result)
batch(asynchronous=True).then(self.batch_result)
self.all_lines_ready.wait(timeout=5)
return "\n".join(self.result)

Expand Down
2 changes: 1 addition & 1 deletion examples/distributed-mandelbrot/client_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self):
raise ValueError("launch at least one mandelbrot calculation server before starting this")
self.mandels = [Pyro4.Proxy(uri) for _, uri in mandels]
for m in self.mandels:
m._pyroAsync() # set them to async mode
m._pyroAsync() # set them to asynchronous mode
for proxy in self.mandels:
proxy._pyroBind()
self.lines = list(reversed(range(res_y)))
Expand Down
2 changes: 1 addition & 1 deletion examples/futures/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ for normal Python functions.
This is just a little extra that Pyro provides, that also works
for normal Python code.

It looks similar to the async proxy support from the `async` example.
It looks similar to the asynchronous proxy support from the `async` example.
2 changes: 1 addition & 1 deletion src/Pyro4/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

# Pyro version
VERSION = "4.64-dev0"
VERSION = "4.64.dev0"

# standard object name for the Daemon object
DAEMON_NAME = "Pyro.Daemon"
Expand Down
10 changes: 5 additions & 5 deletions src/Pyro4/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def _pyroBatch(self):
return _BatchProxyAdapter(self)

def _pyroAsync(self, asynchronous=True):
"""turns the proxy into async mode so you can do asynchronous method calls,
"""turns the proxy into asynchronous mode so you can do asynchronous method calls,
or sets it back to normal sync mode if you set asynchronous=False."""
self.__async = asynchronous

Expand Down Expand Up @@ -843,7 +843,7 @@ def _pyroInvoke(self, name, args, kwargs):


class _AsyncRemoteMethod(object):
"""async method call abstraction (call will run in a background thread)"""
"""asynchronous method call abstraction (call will run in a background thread)"""
def __init__(self, proxy, name, max_retries):
self.__proxy = proxy
self.__name = name
Expand Down Expand Up @@ -882,11 +882,11 @@ def __asynccall(self, asyncresult, args, kwargs):
except (errors.ConnectionClosedError, errors.TimeoutError) as x:
# only retry for recoverable network errors
if attempt >= self.__max_retries:
# ignore any exceptions here, return them as part of the async result instead
# ignore any exceptions here, return them as part of the asynchronous result instead
asyncresult.value = futures._ExceptionWrapper(x)
return
except Exception as x:
# ignore any exceptions here, return them as part of the async result instead
# ignore any exceptions here, return them as part of the asynchronous result instead
asyncresult.value = futures._ExceptionWrapper(x)
return

Expand All @@ -897,7 +897,7 @@ def batch(proxy):


def asyncproxy(proxy, asynchronous=True):
"""convenience method to set proxy to async or sync mode."""
"""convenience method to set proxy to asynchronous or sync mode."""
proxy._pyroAsync(asynchronous)


Expand Down
4 changes: 2 additions & 2 deletions src/Pyro4/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def iferror(self, exceptionhandler):
"""
Specify the exception handler to be invoked (with the exception object as only
argument) when calculating the result raises an exception.
If no exception handler is set, any exception raised in the async call will be silently ignored.
If no exception handler is set, any exception raised in the asynchronous call will be silently ignored.
Returns self so you can easily chain other calls.
"""
self.exceptionhandler = exceptionhandler
Expand Down Expand Up @@ -143,7 +143,7 @@ def wait(self, timeout=None):

@property
def ready(self):
"""Boolean that contains the readiness of the async result"""
"""Boolean that contains the readiness of the asynchronous result"""
return self.__ready.isSet()

def get_value(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/PyroTests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,14 +850,14 @@ def testBatchMethodOneway(self):
results = batch(oneway=True)
self.assertIsNone(results) # oneway always returns None
self.assertEqual(4, len(proxy.result)) # should have done 4 calls, not 5
self.assertRaises(Pyro4.errors.PyroError, batch, oneway=True, asynchronous=True) # oneway+async=booboo
self.assertRaises(Pyro4.errors.PyroError, batch, oneway=True, asynchronous=True) # oneway+asynchronous=booboo

def testBatchMethodAsync(self):
proxy = self.BatchProxyMock()
batch = Pyro4.core.batch(proxy)
self.assertIsNone(batch.foo(42))
self.assertIsNone(batch.bar("abc"))
self.assertIsNone(batch.pause(0.5)) # pause shouldn't matter with async
self.assertIsNone(batch.pause(0.5)) # pause shouldn't matter with asynchronous
self.assertIsNone(batch.baz(42, "abc", arg=999))
begin = time.time()
asyncresult = batch(asynchronous=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/PyroTests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def testBatchAsync(self):
with Pyro4.core.Proxy(self.objectUri) as p:
batch = Pyro4.core.batch(p)
self.assertIsNone(batch.multiply(7, 6))
self.assertIsNone(batch.delay(1)) # a delay shouldn't matter with async
self.assertIsNone(batch.delay(1)) # a delay shouldn't matter with asynchronous
self.assertIsNone(batch.multiply(3, 4))
begin = time.time()
asyncresult = batch(asynchronous=True)
Expand Down

0 comments on commit 2684b1a

Please sign in to comment.