0

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

JavaSa
  • 5,813
  • 16
  • 71
  • 121
  • some programs use simple file like `.lock` (sometimes with some information who is using resources). If file doesn't exist then you can create it and use resources. – furas Jan 25 '17 at 17:43
  • @furas: Do you know of a packages or implementations already around? – JavaSa Jan 26 '17 at 08:05

1 Answers1

0

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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • We need to limit access to the lock files, as it can be that one process wants to remove the lock while in the same time another one wants to remove it also. We need some thread/process safety here, any ideas how to implement that to avoid racing conditions using ftplib, or other packages for handling ftp? – JavaSa Jan 26 '17 at 10:41
  • @JavaSa: I don't understand what you mean. I outlined a full sequence for acquiring and releasing locks. The filesystem will not allow two different programs to create the same file. – John Zwinck Jan 27 '17 at 01:30