Forums

Django_mysql.locks - users releasing other users locks

I have used django_mysql.locks to acquire a lock. This implements the user level locking functions in MySQL This works for the first user. The lock is acquired and held by the first user. On Pythonanywhere a second user logging on from a separate device is able to release this lock using the release lock method.

On my localhost version of the app the second user is not able to release the lock acquired by the first user - it only happens when I deploy the app to Pythonanywhere.

I have reviewed the metadata_locks table in the Performance schema on my local host and I can see the first and second users have different connection id's. I do not have access the Performance Schema on Pythonanywhere.

From the debug code that I have looked at it appears that in Pythonanywhere the connection id for both the first and second user is the same. I used lock.holding_connection_id() to obtain the connection id. If the two users have the same connection id then the lock is not user specific.

It appears that I cannot use django_mysql.locks on Pythonanywhere. Is there something I am missing.

That's probably due to connection pooling - the two users are using the same database connection and therefore the second user is able to release the lock.

Connection pooling looks like the issue. As I have little control over the connection id used for the lock it seems that this means of locking is of no use to me.

If you want, you could share what you are trying to achieve with the locks? Maybe there's another solution.