Issue
All search results on "coroutine was never awaited" are for people who were either trying to fire-and-forget or actually did forget to await. This is not my case.
I want to use a coroutine the same way I often use generators: I'm creating it here while I have all the variables handy, but I'm not sure yet whether I'll ever need that to be run. Something like:
options = {
'a': async_func_1(..., ...),
'b': async_func_2(),
'c': async_func_3(...),
}
and elsewhere:
appropriate_option = figure_the_option_out(...)
result = await options[appropriate_option]
Solution
This might help
import warnings
...
def go(self):
try:
self.loop.run_until_complete(self.run())
except Exception as e:
print(f" {e}")
finally:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self._clean_up()
...
where self._clean_up()
causes the RuntimeWarning
You can suppress warnings temporarily as above. You can read about it more in detail at https://python.readthedocs.io/en/latest/library/warnings.html#temporarily-suppressing-warnings
Answered By - Gergely M
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.