Closed thedrow closed 3 years ago
Since synchronous resources are by definition synchronous, we need to acquire & release them using a thread pool. Therefore, we must wrap them in a ThreadedContextManager which schedules __enter__ and __exit__ in the thread pool.
ThreadedContextManager
__enter__
__exit__
The ThreadedContextManager follows the classic Adapter design pattern.
By default, we use a global CapacityLimiter passed into the anyio.run_sync_in_worker_thread(). The capacity limiter is set to the current number of CPUs.
CapacityLimiter
anyio.run_sync_in_worker_thread()
You may optionally pass another CapacityLimiter instance.
Since synchronous resources are by definition synchronous, we need to acquire & release them using a thread pool. Therefore, we must wrap them in a
ThreadedContextManager
which schedules__enter__
and__exit__
in the thread pool.The
ThreadedContextManager
follows the classic Adapter design pattern.By default, we use a global
CapacityLimiter
passed into theanyio.run_sync_in_worker_thread()
. The capacity limiter is set to the current number of CPUs.You may optionally pass another
CapacityLimiter
instance.