Steven D'Aprano wrote: > Let me see if I understand your problem... you need to edit a text file > in place at the same time that another process is also changing the file > in place? That's hard. You need some way to decide who gets precedence if > both you and the other process both try to change the same line > simultaneously. > > I think the only way this is even half-doable will be if: > > - the other process writing to the file only appends to the end of the > file, and does not try to write to the middle; > > - the new line you are writing is the same length as the old line you are > replacing; > > - and you are running an operating system that allows two processes to > have simultaneous write access to a file. > > What problem are you trying to solve by having simultaneous writes to the > same file? Perhaps there is another way. > > Thanks for your reply.
I would have no problem to let other processes finish their writing duty to the file and my script only gets access when no other process is working with the file. The file written to is the hosts.allow file which is changed often by the blockhosts.py script when some ssh access is attempted. Now blockhosts.py works great , but sometimes our mobile clients try to access from ip addresses which are completely blocked to avoid the thousands of scripted attacks showing up in our logs. Now our authorized clients register themselves automatically with computername,id and ip address via a small python script which sends this information to a firebird database on our server. A serverside script scans the database ever so often and changes the hosts.allow file to enable authorized clients to log on via ssh if they have moved out of their original areas ( like traveling from china to india and logging in from a hotel room) Most of the clients run Suse9.3 so does the server some are wxp machines which get their ssh access via winscp or putty if needed. Every client has a marker in the hosts.allow file so if a change occurs one line shall be replaced by another line on the fly. I hope this describes it. Nx -- http://mail.python.org/mailman/listinfo/python-list