Skip to content

Fix the asyncio example ioc, and documentation #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Added:

Fixed:

- `Update asyncio example to use dispatcher for custom function <../../pull/94>`_
- `Passing a custom asyncio event loop into the AsyncioDispatcher causes methods to never run <../../pull/96>`_

4.0.2_ - 2022-06-06
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example_asyncio_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def update():
ai.set(ai.get() + 1)
await asyncio.sleep(1)

asyncio.run_coroutine_threadsafe(update(), dispatcher.loop)
dispatcher(update)

# Finally leave the IOC running with an interactive shell.
softioc.interactive_ioc(globals())
5 changes: 3 additions & 2 deletions docs/how-to/use-asyncio-in-an-ioc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ this.

The ``async update`` function will increment the value of ``ai`` once per second,
sleeping that coroutine between updates.
Note that we run this coroutine in the ``loop`` of the ``dispatcher``, and not in the
main event loop.
Note that we pass this coroutine to the ``dispatcher``, which will execute it in the
dispatcher's own event loop and not in the main event loop. It also provides some logging
if exceptions occur.

This IOC will, like the one in `../tutorials/creating-an-ioc`, leave an interactive
shell open. The values of the PVs can be queried using the methods defined in the
Expand Down
2 changes: 1 addition & 1 deletion softioc/asyncio_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ async def async_wrapper():
if completion:
completion(*completion_args)
except Exception:
logging.exception("Exception when awaiting callback")
logging.exception("Exception when running dispatched callback")
asyncio.run_coroutine_threadsafe(async_wrapper(), self.loop)