Python and Advanced PostgreSQL with psycopg2 - Locking in PostgreSQL