iotile / iotile/coretools

Improve visibility of exceptions in asyncio routines, especially within 'run_in_executor'

Open
#851 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14
Forks
7
PR merge metrics
No merged PRs in 30d

Description

The following code stalled at the await future line:

```
def _validate_thread(self):
proc = subprocess.run('echo hello', shell=True)
print("This causes an exception: ", proc.returncode())
return proc.returncode

async def validate(self):
"""Verify that the system is running and ready to commit an update"""
self._logger.info("Starting Validate")
future = SharedLoop.run_in_executor(self._validate_thread)

print("started process")
self._logger.info("Waiting for validation to complete")
rc = await future
```

This is because of the exception in the print statement.

The error is visible while the tasks are being cleaned up during a CTRL+C, but can become somewhat lost in output among all the other cleanup that occurs.

Reporting the exception in real time (perhaps with a certain amount of -v's) would be very helpful, as would be raising the visibility of the error print during cleanup. I'd suggest printing the stack or coloring the line red.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.