Skip to content
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

Update asyncio example to show exceptions in long running functions being tracked #94

Closed
coretl opened this issue Jun 21, 2022 · 0 comments · Fixed by #99
Closed

Update asyncio example to show exceptions in long running functions being tracked #94

coretl opened this issue Jun 21, 2022 · 0 comments · Fixed by #99

Comments

@coretl
Copy link
Contributor

coretl commented Jun 21, 2022

This is a failing of the example code. We put some exception handling in the dispatcher, so if an function passed to on_update fails we get the traceback printed, but we don't do anything with the long running update function in the example. We can make use of the same exception handling by scheduling it with the dispatcher:

...
# Start processes required to be run after iocInit
async def update():
    while True:
        ai.set(ai.get() + 1)
        await asyncio.sleep(1)
        raise Exception("Boom")

dispatcher(update)

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

This now prints

Starting iocInit
############################################################################
## EPICS 7.0.6.1
## Rev. 7.0.6.99.2.0
############################################################################
iocRun: All initialization complete
Python 3.7.2 (default, Jan 20 2020, 11:03:41) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ERROR:root:Exception when awaiting callback
Traceback (most recent call last):
  File "/dls/science/users/tmc43/common/python/pythonSoftIOC/softioc/asyncio_dispatcher.py", line 35, in async_wrapper
    await ret
  File "example_asyncio_ioc.py", line 26, in update
    raise Exception("Boom")
Exception: Boom

The logging message isn't the best though, I'll make an issue to track this

Originally posted by @coretl in #93 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant