A lock would be one solution, but with Twisted there's another approach. You can basically move the copy of the dict to outside of of _update() and pass it to deferToDatabase(). That way you get an automatic lock for the connections dict, since both the copy and the modifications run in the main thread.
A lock would be one solution, but with Twisted there's another approach. You can basically move the copy of the dict to outside of of _update() and pass it to deferToDatabase(). That way you get an automatic lock for the connections dict, since both the copy and the modifications run in the main thread.