pythonpython-2.7operating-systemlocksreaderwriterlock

Reader writer lock with preference to writers


For this question simplictly , I'm having two types of computers: type A and B.
There is one computer of type A, and many of type B.

B are type of hosts which can write and read from ftp. A is a computer which can just read from ftp.

As you might already guess, ftp is the shared area which need to be protected by readers-writers lock solution.

Does anybody knowns of an already existing python package which handle this scenario, if not, do anybody has an example how can it be implemented for such need?

I guess that some locks should be implemented as files on ftp, since we are dealing with processes from different hosts.

Thanks


Solution

  • Writer:

    1. Upload a file W. If this fails, wait and try again.
    2. Upload a file R. If this fails, wait and try again.
    3. Do as many writes as desired.
    4. Remove W.
    5. Remove R.

    Reader:

    1. Upload a file R. If this fails, wait and try again.
    2. Check for the existence of a file W. If it exists, remove R and return to step 1.
    3. Do one read. If multiple reads are needed, return to step 2.
    4. Remove R.

    You can use the Python module ftplib (or for SFTP, paramiko) to implement the above operations.