I have this code:
try:
asyncio.ensure_future(data_streamer.sendByLatest())
except ValueError as e:
logging.debug(repr(e))
data_streamer.sendByLatest()
can raise a ValueError
, but it is not caught.
I have this code:
try:
asyncio.ensure_future(data_streamer.sendByLatest())
except ValueError as e:
logging.debug(repr(e))
data_streamer.sendByLatest()
can raise a ValueError
, but it is not caught.
ensure_future
- just createsTask
and return immediately. You should await for created task to get it's result (including case when it raises exception):Output:
In case you aren't planning to await task immediately after you created it, you can await it later (to know how it has finished):
Output is same: