#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0

    files over the web


    I have a python script that saves info to a .csv file. If two or more ppl are trying to access it the same time will the file lock and prevent one from opening and submitting to it or does it not matter beacuse of the client/server architecture of the webbrowser?
    is there a way to circumvent this in python perhaps catching the exception?
    do i HAVE TO use a relational database to circumvent this problem? Please say no.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I can't really test this right now but in theory the file should be locked - two file streams can't write to the file at the same time, or if they do your file gets wiped.

    Your earlier post might be relivant here too - http://forums.devshed.com/t140081/s.html

    You could always try locking the file manually just to be sure.

    Another way to do this would be to check if the file is accessable using os.access() although i havn't used this at all:

    http://www.python.org/doc/2.3.3/lib/os-file-dir.html

    You should also be able to use a try-except block to check if a file is writeable or not.

    All options to consider, hope this helps.

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    Thanks for the reply. Sorry about the double post. I didn't receive an email telling me anyone had responded. I think i might just have to use a rdms. Thanks.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thats ok, not a problem at all. You might want to look at PySQLite for small projects where you really dont need to use MySQL although MySQL is ideal for web applications IMO.

    Even if the current DBI is a little long winded for my tastes; again just an oppinion .

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    actaully was thinking about using sqlite. i had just read up on it and it said there was some things that still were not implemented. i'll check it out again. by the way sql lite can hold up to 2 terabytes of info. That is pretty significant. unless other databases hold more. never used a db before.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    okay, i had the txt file opened and then i went online and wrote in the form to see if i would get an error when i submitted to the same file. however the infomation was submitted to the file still. does that mean that the file isn't locked and two or more ppl can submit at the same time. I'm really not expecting a lot of traffic on the site. or did i test it wrong.?
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  12. #7
  13. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Just because you open a file to read or write does not mean you have a lock on it. There are OS specific ways to get a file lock at the system level.
    Doing a search for python file lock threw up this:
    http://aspn.activestate.com/ASPN/Coo...n/Recipe/65203

    From what you say - it's not going to be a problem in practice. Just write the logging code in some function. That way if you ever have to upgrade your logging you just change the core of the function.

    Grim
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep Power
    0
    for now i just want multiple users to write to the files so i'll just save it as .txt and have it comma delimited then i look at it, i'll save it as a csv file. that'll be easier for me - for now. later i'll look into implementing a database. Still weird how a csv file will lock and a text file won't.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."


IMN logo majestic logo threadwatch logo seochat tools logo