A context manager written with @contextmanager leaves a lock held whenever the with body raises. What is missing from the generator?
A try/finally around the yield. @contextmanager throws the body's exception into the generator at the yield, so a release written after the yield is skipped. Wrap the yield in try/finally, or use with lock inside it, and re-raise anything you catch, or the generator suppresses the caller's error.