Turn DWaveSampler into context manager
Blocked by https://github.com/dwavesystems/dwave-system/issues/77.
One thing we could do is only keep the thread pool open if inside a context. So
sampler = DWaveSampler()
sampler.sample_ising(...)
sampler.sample_ising(...)
would be equivalent (from a cloud-client perspective) to
with DWaveSampler() as sampler:
sampler.sample_ising(...)
with DWaveSampler() as sampler:
sampler.sample_ising(...)
where as
with DWaveSampler() as sampler:
sampler.sample_ising(...)
sampler.sample_ising(...)
would only open one thread pool.
However this would impact performance pretty significantly in the case of multiple calls outside of a context manager. Probably better to do the singleton threadpool mentioned by @randomir in https://github.com/dwavesystems/dwave-system/issues/171#issuecomment-480991050.
@arcondello, I think we'll soon have singleton threadpools, as they are related to https://github.com/dwavesystems/dwave-cloud-client/issues/326.