Context manager generator for retry block pattern and decorator.

You could probably coordinate two threads to explicitly capture the isolation levels and ensure that they're working correctly. For instance, you could have a list of actions that combine the queue and the action, so that you can specify exactly the ordering each thread should do the relevant database operations.