Skip to content

Commit d06e9f7

Browse files
Fix the asyncio example ioc, and documentation
Also tweak the wording on the exception logging
1 parent f9960ce commit d06e9f7

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Added:
1616

1717
Fixed:
1818

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

2122
4.0.2_ - 2022-06-06

docs/examples/example_asyncio_ioc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def update():
2323
ai.set(ai.get() + 1)
2424
await asyncio.sleep(1)
2525

26-
asyncio.run_coroutine_threadsafe(update(), dispatcher.loop)
26+
dispatcher(update)
2727

2828
# Finally leave the IOC running with an interactive shell.
2929
softioc.interactive_ioc(globals())

docs/how-to/use-asyncio-in-an-ioc.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ this.
2121

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

2728
This IOC will, like the one in `../tutorials/creating-an-ioc`, leave an interactive
2829
shell open. The values of the PVs can be queried using the methods defined in the

softioc/asyncio_dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ async def async_wrapper():
4646
if completion:
4747
completion(*completion_args)
4848
except Exception:
49-
logging.exception("Exception when awaiting callback")
49+
logging.exception("Exception when running dispatched callback")
5050
asyncio.run_coroutine_threadsafe(async_wrapper(), self.loop)

0 commit comments

Comments
 (0)