It's probably more elegant to make this an instance function, so you do:
```python
with self.lock(name, value):
    setattr(self, name, value)
```