Skip to content

Commit bdc061a

Browse files
committed
Ref #701 -- Do not copy context to threads
asyncio.to_thread copies the context and passes it to the thread. This will create a larger memory foodprint and may cleave objects in memory for too long
1 parent 9c014a0 commit bdc061a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

health_check/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ def pretty_status(self) -> str:
7474
return "OK"
7575

7676
async def get_result(self: HealthCheck) -> HealthCheckResult:
77+
loop = asyncio.get_running_loop()
7778
start = timeit.default_timer()
7879
try:
7980
await self.run() if inspect.iscoroutinefunction(
8081
self.run
81-
) else await asyncio.to_thread(self.run)
82+
) else await loop.run_in_executor(None, self.run)
8283
except HealthCheckException as e:
8384
error = e
8485
except BaseException:

0 commit comments

Comments
 (0)