OMERO.py client and services that works with asyncio.
For example, compare the time taken to run multiple HQL queries in example.py serially (serial=True, around 3 seconds) and concurrently (serial=False, around 1 second).
Use this if you are using the standard (synchronous) omero.client and want easy access to async services.
For example:
client = omero.client(HOST)
session = client.createSession(USERNAME, PASSWORD)
qs = AsyncService(session.getQueryService())
result = await qs.findAllByQuery('From Project', None)Note due to differences in the positions of the underlying async keyword parameters if you need to pass an Ice context parameter this must be a named argument _ctx=ctx.
This is a modified version of the default omero.client with an async implementation of createSession.
Services are automatically converted to async.
For example:
client = AsyncClient(HOST)
session = await client.createSession(USERNAME, PASSWORD)
qs = await session.getQueryService()
result = await qs.findAllByQuery('From Project', None)In Ice 3.6 all synchonous methods also have asynchronous versions prefixed with begin_ and end_.
If callbacks are used it is possible to avoid explicitly calling end_ when the asynchronous call finishes.
With a bit of additional wrapping it is possible to integrate these Ice asynchronous calls into Python's asyncio framework.
A wrapper class AsyncService is used to wrap Ice services to automatically convert all methods to their async form.
Note in Ice 3.7 this would be a lot easier as Ice provides a wrapper to return asyncio.Futures directly.
Also note that although this enables concurrent Ice calls it is still restricted to a single thread.