Protect loop set default executor (#37438)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus SchoutsenandJ. Nick Koston authored and GitHub committed 2020-07-06 15:58:53 -07:00
1 parent f8651d9faa
commit f49ce5d1b4
21 files changed
+387 -244

No files matched your search

+10 -9
View File
@@ -36,18 +36,19 @@ def run(args):
args = parser.parse_args()
bench = BENCHMARKS[args.name]
print("Using event loop:", asyncio.get_event_loop_policy().__module__)
print("Using event loop:", asyncio.get_event_loop_policy().loop_name)
with suppress(KeyboardInterrupt):
while True:
loop = asyncio.new_event_loop()
hass = core.HomeAssistant(loop)
hass.async_stop_track_tasks()
runtime = loop.run_until_complete(bench(hass))
print(f"Benchmark {bench.__name__} done in {runtime}s")
loop.run_until_complete(hass.async_stop())
loop.close()
asyncio.run(run_benchmark(bench))
async def run_benchmark(bench):
"""Run a benchmark."""
hass = core.HomeAssistant()
runtime = await bench(hass)
print(f"Benchmark {bench.__name__} done in {runtime}s")
await hass.async_stop()
def benchmark(func: CALLABLE_T) -> CALLABLE_T: